?
Solved

doesnt this get rid of newlines in a string ?

Posted on 2004-09-29
13
Medium Priority
?
224 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 300 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
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!

 
LVL 12

Assisted Solution

by:minichicken
minichicken earned 100 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 100 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …
Suggested Courses

777 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