Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

str_replace = i need to remove an empty line from my string PLS HELP

Posted on 2011-09-22
2
Medium Priority
?
275 Views
Last Modified: 2012-05-12
My string contains an extra empty line, how can i remove it or replace it?

I am using a .php code for this and i can't make it work
$mystring str_replace("/n","",$mystring)
echo $mystring;

Thanks
0
Comment
Question by:parpaitas
2 Comments
 
LVL 2

Expert Comment

by:shdwmage
ID: 36583257
This is what I use to remove all carriage returns in my input.

function data_correction($beta) {
	//this function is used to replace data copied and pasted from excel to make it into a useable format.
	$newstr = str_replace("\r\n", ",", $beta);
	return $newstr;
};

Open in new window


I paste information from excel and I don't like to seperate it into commas.  Hope that helps.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 36583389
This is not a valid PHP statement.  It needs an assignment operator.  And /n is not the same as \n
$mystring str_replace("/n","",$mystring)

Try something more like this:
$mystring = str_replace("\n", NULL, $mystring);

Also, you might want to know about the context-aware constant, PHP_EOL.  It is the end-of-line character.

But all that aside, we cannot really tell what your data looks like or what you want it to look like.  If you want to post your string with the blank line, I will be glad to show you the code you need to remove the empty line.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question