[thelist] ereg_replace \n having some probs

Dunstan Orchard dunstan at 1976design.com
Wed Jan 22 07:33:01 CST 2003


Hi there,

I'm trying to format some text that I'm grabbing from a db.

I currently do this to cope with new lines in the users' input:

$news = $row["news"];
$news = stripslashes($news);
 // if they pressed return once, put in line break
 $news = ereg_replace("\n","<br />\r\n",$news);

<p>$news</p>


But what I'd like to do is allow people to decide if they want a new line or a
new paragraph:

$news = $row["news"];
$news = stripslashes($news);
 // if they've pressed return twice, then put in paragraph tags
 $news = ereg_replace("\n\n","</p>\r\n<p>",$news);
 // if they pressed return once, put in line break
 $news = ereg_replace("\n","<br />\r\n",$news);


However, that doesn't work. The two return presses aren't picked up buy this -
I just end up with two br tags.

Any ideas?

Thanks very much - dunstan

---------------------------
Dorset, England
http://www.1976design.com/
http://www.orchard.it/
http://www.maccaws.org/



More information about the thelist mailing list