Re: stripping newlines from a string
| From: | Lars Torben Wilson | Date: | Mon, 09 Jun 2003 07:01:44 +0000 |
| Subject: | Re: stripping newlines from a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-150719@lists.php.net to get a copy of this message | ||
On Sun, 2003-06-08 at 22:44, Charles Kline wrote:
> Hi all,
>
> How would i go about stripping all newlines from a string?
>
> Thanks,
> Charles
Something like this:
<?php
error_reporting(E_ALL);
$str = "This string has unix\n and Windows\r\n and Mac\r line endings.";
$new_str = preg_replace('/[\n\r]+/', '', $str);
echo "$str; $new_str";
?>
Good luck,
Torben
--
Torben Wilson <torben@php.net> +1.604.709.0506
http://www.thebuttlesschaps.com http://www.inflatableeye.com
http://www.hybrid17.com http://www.themainonmain.com
-----==== Boycott Starbucks! http://www.haidabuckscafe.com ====-----