automatically parsing new lines

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

automatically parsing new lines

Post by fariquzeli »

I have a text area in which press releases are made, when copying and pasting the text into the textarea field the paragraphs are preformatted to have breaks inbetween them, yet when submitted to the db, and pulled back out of the db on a seperate page, the breaks don't show up and the text is shown as one big block.

I have to manually put in the <BR> after each paragraph, is there a way to get the field to automatically make those breaks? I know it can be done. On deviantart.com when putting info into a text field, if you hit return twice it is parsed as 2 <BR><BR>'s
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

of course, anything with PHP!

u'll have to do a little replacing when u get from the database...here's the code i use:

Code: Select all

<?php $listquery = "SELECT * FROM forum where forumname="general"";
$listresult = mysql_query($listquery);
while ($row = mysql_fetch_assoc($listresult)) &#123;
        $message =  $row&#1111;"msg"];
	&#1111;b]$search = array("/\n/");
	$replace = array("<br>\n");
	$message = preg_replace($search, $replace, $message);
	echo $message;&#1111;/b]
&#125; ?>
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

works wonderfully, thanks a bunch!
Post Reply