Re: newline to <p>?

From: Date: Tue, 29 Aug 2000 10:07:43 +0000
Subject: Re: newline to <p>?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-14091@lists.php.net to get a copy of this message
miryadi@indo.net.id writes: > thanks for your reply, > > i've tried > $variable = ereg_replace("\n \n","<P>",$variable); > and > $variable = ereg_replace("\n\n","<P>",$variable); > but it doesn't work :( > > if someone can give me a clue what does nl2br function do, > (the code of nl2br) maybe i can solve my problem. Well, the code is freely available, but I don't think you'd need it for this. You could use something close to the above, but you'd need 3 slashes before each 'n': one for the escape character, one for the double quotes, and one for the regex string interpretation (for a total of 3 slashes). If you know that the newlines are always going to be directly consecutive, you can skip the regex and just use str_replace(): $newtext = str_replace("\n\n", '<p>', $text); ...but if you want to translate things like a blank line with some whitespace on it, you could do something like this with ereg_replace(): $newtext = ereg_replace("\\\n[ \t]*\\\n", '<p>', $text); Cheers, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#14091) next »