Re: [PHP] Re: Replacing newlines (\n) with smething else
But what if say I want to replace a newline with something else, say /pp. How would I do that? (with apologies for the lack of imagination :-P) ?php $George = Hello\n\tall\nyou\nfriendly people; echo 'George: ' . $George . \n; $Henry = str_replace( \n, /p\np, $George ); $Henry = 'p' . $Henry . /p\n; echo 'Henry: ' . $Henry . \n; $Helen = Kindest\r\tgreetings\nto all\r\nyou\n\rwonderful people; echo 'Helen: ' . $Helen . \nSee what that \\r does?\n\n; $Marion = str_replace( \r, \n, $Helen ); $Marion = str_replace( \n\n, \n, $Marion ); $Marion = str_replace( \n, /p\np, $Marion ); $Marion = 'p' . $Marion . /p\n; echo 'Marion: ' . $Marion . \n; $Juliet = preg_replace( '/([^\r\n]*)(\r\n|\n\r|\r|\n)/', p\${1}/p\n, $Helen ); $Juliet = preg_replace( '/([^\r\n]+$)/', p\${1}/p\n, $Juliet ); echo 'Juliet: ' . $Juliet . \n; ? -- Joel Rees, programmer, Kansai Systems Group Altech Corporation (Alpsgiken), Osaka, Japan http://www.alpsgiken.co.jp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Replacing newlines (\n) with smething else
Jason Giangrande [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I'm trying to replace newlines with something else. For this example I'll use br as the thing to replace a newline with. This is what I tried and it doesn't work. $article = str_replace(\n, br, $article); What am I doing wrong? $article is the string to replace the newlines in. I tried this with a period and that works as expected. Can I not replace newlines this way? why not just: $article = nl2br($article); -- J. Cox http://www.xaraya.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Replacing newlines (\n) with smething else
I did not know about nl2br. Thanks. But what if say I want to replace a newline with something else, say /pp. How would I do that? Jason On Sun, 2003-07-13 at 17:09, J. Cox wrote: Jason Giangrande [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I'm trying to replace newlines with something else. For this example I'll use br as the thing to replace a newline with. This is what I tried and it doesn't work. $article = str_replace(\n, br, $article); What am I doing wrong? $article is the string to replace the newlines in. I tried this with a period and that works as expected. Can I not replace newlines this way? why not just: $article = nl2br($article); -- J. Cox http://www.xaraya.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php