Re: trim...
| From: | Justin Patrin | Date: | Wed, 26 Nov 2003 17:44:08 +0000 |
| Subject: | Re: trim... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171109@lists.php.net to get a copy of this message | ||
trim also gets rid of leading spaces...
Mike Ford wrote:
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