Click to See Complete Forum and Search --> : [RESOLVED] how do i preserve formatting extracting TEXT type mysql field?


hitecbill
07-04-2006, 04:03 AM
how do i preserve formatting extracting TEXT type mysql field?

i have some text in a mysql field that contains %0A%0D etc but when i select and display they disappear, i.e. it just displays as one paragraph devoid of control chars?

what's a bit weird is, if i view source, it shows the text with CR's and LF's!

:cool:

hitecbill
07-04-2006, 07:01 AM
you see the 0A and 0D's in the hex dump?

http://img150.imageshack.us/img150/5761/crlf9lm.gif

they're ascii values, so i need to read and convert ascii vales into html...bah!

:confused:

NogDog
07-04-2006, 09:16 AM
Two choices: use the nl2br() function (http://www.php.net/nl2br), or embed the output in <pre>...</pre> tags. The choice will depend on whether you want the no-wrap formatting that <pre> also imposes, or just want <br/> tags at each newline in the text.

hitecbill
07-04-2006, 09:33 AM
Two choices: use the nl2br() function (http://www.php.net/nl2br), or embed the output in <pre>...</pre> tags. The choice will depend on whether you want the no-wrap formatting that <pre> also imposes, or just want <br/> tags at each newline in the text.
hi thx for the reply...again, nogdog helping out!

:)

hmm, yeah <pre> kinda worked...but also imposed no wrap, as you stated...

i actually fixed it, in my own dum way...i am so not a regex bloke, btw...

i thought why not pump the standard "/n" notation into ereg_replace...for cr/lf in and it worked...(i had been tyring %0A and %0D)...

$string = ereg_replace("\n", "<br />", $field[2]);
echo "$string<br /><br />";

($field[2] being one of the fields returned from a mysql_query)

this is 'resolved' now...

cheers,
bill