doesnt this get rid of newlines in a string ?

doesnt this get rid of newlines in a string ?


$string = ereg_replace ("\n", "", $string);

-->this is not working !!!    
$tmp= ereg_replace ("\n", "", $results2['DESC'][0]);

LVL 1
aot2002Asked:
Who is Participating?
 
nicholassolutionsConnect With a Mentor Commented:
sorry should have been:

$string = ereg_replace("\r?\n?", "", $string);

it's essentially the same idea as the solution by sajuks -- on different systems, the "\n" may not be what is used for a newline.

Cheers,
Matt
0
 
sajuksCommented:
try this way
$replace = array ("\n","\r");
$string = str_replace($replace,'',$string);
0
 
nicholassolutionsCommented:
try this:

$string = ereg_replace("\r?\n", "", $string);

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
minichickenConnect With a Mentor Commented:
Try use chr(13) instead of "\n"

$string = str_replace (chr(13), "", $string); //chr(13) is the ASCII code for the ENTER key

Hope this helps

j311y :)
0
 
Georgiana GligorCTO / OwnerCommented:
I think it should be:
$tmp= ereg_replace ('\n', "", $results2['DESC'][0]); // simple quotes instead of double quotes

Georgiana
0
 
minichickenCommented:
Maybe also try:

$string = ereg_replace (chr(13), "", $string);
0
 
RoonaanConnect With a Mentor Commented:
Sajuks way should do the trick. It is clumpsy to use ereg for this kind of straightforward replaces.

And even if you did it, you should use something like: $string = ereg_replace("[\n\r]", '', $string);

Regards

-r-
0
 
aot2002Author Commented:
wow holy answers !
let me try these and get right back to you
0
 
aot2002Author Commented:
$parttypedesc = ereg_replace("\r?\n?", "", $results2['PART_TYPE_DESC'][0]);

This worked GREAT THANKS !
0
 
aot2002Author Commented:
Comment from gicutza_cj  feedback
Date: 09/30/2004 03:17AM EDT
 Comment  


I think it should be:
$tmp= ereg_replace ('\n', "", $results2['DESC'][0]); // simple quotes instead of double quotes

Georgiana


THIS DIDNT WORK i do know from experience that \n wont work in single quotes unless something has changed
0
 
RoonaanCommented:
You know that ereg is executed slower than str_replace is, although minimal it's something to keep in mind.

-r-
0
 
aot2002Author Commented:
thanks i didnt know this i always wondered why php site pointed everything to ereg not str_replace ?
are they removing str_replace ?
0
 
RoonaanCommented:
no. some people just think because ereg looks complicated, it looks impressive when they use it, I suppose.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.