RE: [PHP] trim...

From: Date: Wed, 26 Nov 2003 17:12:52 +0000
Subject: RE: [PHP] trim...
Groups: php.general 
Request: Send a blank email to php-general+get-171100@lists.php.net to get a copy of this message
On 26 November 2003 16:59, Tristan.Pretty@risk.sungard.com contributed these pearls of wisdom: > Why doesn't this work...? > > $body = " > <p>blurb blah > <p>happy days > <p>end of text"; > > $body = trim($body); > > $body now should output: > "<p>blurb blah\n<p>happy days\n<p>end of text" but it > doesn't...? No it shouldn't -- it should output exactly what you've put into the string, minus any trailing spaces (of which there aren't any). trim() has nothing to do with escapifying newline characters. If you wnat your text output to javascript with \n in them, then that's exactly what you should put in them -- either that, or run a str_replace() to turn the newlines into \n sequences. So: $body = "<p>blurb blah\\n<p>happy days\\n<p>end of text"; echo $body or $body = " <p>blurb blah <p>happy days <p>end of text"; echo str_replace("\n", '\n', $body); Cheers! Mike -- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#171100) next »