Page 1 of 1

automatically parsing new lines

Posted: Wed Jul 31, 2002 1:18 pm
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

Posted: Wed Jul 31, 2002 1:24 pm
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; ?>

Posted: Wed Jul 31, 2002 1:45 pm
by fariquzeli
works wonderfully, thanks a bunch!