[thelist] simple PHP problem

Jason Morehead jmorehead at alphalincoln.com
Thu Oct 5 09:24:05 CDT 2000


>To clarify: If i was to call two paragraphs of text
>from the same field in my Mysql table, that were
>seperated by a double space, would it possible with
>PHP, to dynamicaly add <P> tags to the begining of
>each paragraph so that when the brower reads it the
>text retains it's orginal formating instead of being
>outputed to the browser as one long piece of text.

there are a couple of ways to do this.  you could use php's nl2br() 
function, which will replace all newlines with <br> tags.  on my 
site, i've used the eregi_replace() function to search for linebreaks 
and replace them with the appropriate paragraph tags.

	echo eregi_replace("\r\n\r", "\r</p>\n\n<p>\r", $field);

replace $field with the name of database field that contains the text 
you're outputting to the browser.  you don't need to use the specific 
parameters i've set... i set those more because i like my code 
formatted in a certain way.  in other words, i'm anal.

jason
-- 
http://www.alphalincoln.com/
alphagraphics of nebraska - web services
201 n 14th - lincoln, ne 68508 - 402.475.0000




More information about the thelist mailing list