Solved

doesnt this get rid of newlines in a string ?

Posted on 2004-09-29
13
217 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
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 33

Expert Comment

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

Expert Comment

by:nicholassolutions
Comment Utility
try this:

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

0
 
LVL 15

Accepted Solution

by:
nicholassolutions earned 75 total points
Comment Utility
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
 
LVL 12

Assisted Solution

by:minichicken
minichicken earned 25 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Maybe also try:

$string = ereg_replace (chr(13), "", $string);
0
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 49

Assisted Solution

by:Roonaan
Roonaan earned 25 total points
Comment Utility
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
Comment Utility
wow holy answers !
let me try these and get right back to you
0
 
LVL 1

Author Comment

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

This worked GREAT THANKS !
0
 
LVL 1

Author Comment

by:aot2002
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
no. some people just think because ereg looks complicated, it looks impressive when they use it, I suppose.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now