Solved

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

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 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