Solved

doesnt this get rid of newlines in a string ?

Posted on 2004-09-29
13
223 Views
Last Modified: 2008-03-10
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
Comment
Question by:aot2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 33

Expert Comment

by:sajuks
ID: 12186935
try this way
$replace = array ("\n","\r");
$string = str_replace($replace,'',$string);
0
 
LVL 15

Expert Comment

by:nicholassolutions
ID: 12186941
try this:

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

0
 
LVL 15

Accepted Solution

by:
nicholassolutions earned 75 total points
ID: 12186948
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
Industry Leaders: 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!

 
LVL 12

Assisted Solution

by:minichicken
minichicken earned 25 total points
ID: 12187461
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
 
LVL 4

Expert Comment

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

Georgiana
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12187650
Maybe also try:

$string = ereg_replace (chr(13), "", $string);
0
 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 25 total points
ID: 12187818
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
 
LVL 1

Author Comment

by:aot2002
ID: 12193085
wow holy answers !
let me try these and get right back to you
0
 
LVL 1

Author Comment

by:aot2002
ID: 12193103
$parttypedesc = ereg_replace("\r?\n?", "", $results2['PART_TYPE_DESC'][0]);

This worked GREAT THANKS !
0
 
LVL 1

Author Comment

by:aot2002
ID: 12193138
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
 
LVL 49

Expert Comment

by:Roonaan
ID: 12193158
You know that ereg is executed slower than str_replace is, although minimal it's something to keep in mind.

-r-
0
 
LVL 1

Author Comment

by:aot2002
ID: 12193298
thanks i didnt know this i always wondered why php site pointed everything to ereg not str_replace ?
are they removing str_replace ?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12193372
no. some people just think because ereg looks complicated, it looks impressive when they use it, I suppose.
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

687 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