Re: explode string at new line
| From: | Paul Novitski | Date: | Wed, 06 Jun 2007 06:27:37 +0000 |
| Subject: | Re: explode string at new line | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-256158@lists.php.net to get a copy of this message | ||
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