trim also gets rid of leading spaces...

Mike Ford wrote:
On 26 November 2003 16:59, [EMAIL PROTECTED] 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


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to