Solved

doesnt this get rid of newlines in a string ?

Posted on 2004-09-29
13
222 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

726 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