Re: explode string at new line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 6/5/2007 10:50 PM, Jim Lucas wrote:
Windows uses \r\n newlines; *nix uses \n; Mac uses \r.
...
PHP Code:
$txt = preg_replace('/\r\n|\r/', "\n", $txt);


Another way to write that PCRE pattern is /\r\n?/ (one carriage return followed by zero or one linefeed).

I recall also running into \n\r although I can't recall which system uses it.

As an alternative to PCRE, we can pass arrays to PHP's replace functions, e.g.:

        $txt = str_replace(array("\r\n", "\n\r", "\r"), "\n", $txt);

Regards,

Paul
__________________________

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux