• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

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]);

0
aot2002
Asked:
aot2002
  • 4
  • 3
  • 2
  • +3
3 Solutions
 
sajuksCommented:
try this way
$replace = array ("\n","\r");
$string = str_replace($replace,'',$string);
0
 
nicholassolutionsCommented:
try this:

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

0
 
nicholassolutionsCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
minichickenCommented:
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 GligorCommented:
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
 
RoonaanCommented:
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now