Solved

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

Posted on 2011-09-22
2
261 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 109

Accepted Solution

by:
Ray Paseur earned 500 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

860 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