php3-list | 199908

[PHP3] \n's et al From: christopher wright (chris <email protected>)
Date: 08/31/99

Hi

I have a text string being placed into a mysql field from a textarea form,
hence it contains all manner of newlines and other nasties.

I want to take that string and replace any kind of newline with a \n so that
I can end up with one long line of text suitable to stick into a javascript
variable without getting unterminated string constant errors.

So far I've tried just about everything I can think of with eregi_replace's,
nl2br followed by eregi's on the BR produced etc, but nothing seems to be
able to detect two newlines - i.e. a line of whitespace. Why won't this
code produce me one long line of characters with \n instead of actual line
breaks for example:

$nq=nl2br($foo); // foo is my string...
$nq=eregi_replace("<br>","\\n",$nq);

I tried eregi_replace("\n","\\n",$foo) too - same thing. Lines terminating
in a single newline are escaped no problem, but a blank line ain't
happening. Is there a function to return the character code of a string in
PHP so I can just run through and check exactly what controls are in there?

Any advice would be most appreciated.

Christopher
Wonderstore Developments Ltd
T.F. +44 171 6811870
www.wonderstore.com
creators of www.sometimefriday.com

-- 
PHP 3 Mailing List <http://www.php.net/>
To unsubscribe, send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest, e-mail: php3-digest-subscribe <email protected>
To search the mailing list archive, go to: http://www.php.net/mailsearch.php3
To contact the list administrators, e-mail: php-list-admin <email protected>