Re: Re: [PHP3] Removing ontrol characters
| From: | Andrei Zmievski | Date: | Fri, 30 Jun 2000 18:18:44 +0000 |
| Subject: | Re: Re: [PHP3] Removing ontrol characters | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4088@lists.php.net to get a copy of this message | ||
On Fri, 30 Jun 2000, Richard Lynch wrote:
> In article <394D6BA4.3CA47A0@capecod.net>, cwieden@capecod.net (Clif
> Wieden) wrote:
>
> > Is there a way in PHP to remove all control characters from a string? In
> > particular line feeds, carriage returns, etc.
>
> There's probably a faster regex way, but...
>
> function stripcontrol($string){
> $result = '';
> for ($i = 0; $i < strlen($string); $i++){
> if (ord($string[$i]) > 31){
> $result .= $string[$i];
> }
> }
> return $result;
> }
Or:
$string = preg_replace("/[\\x00-\\x1f]+/", "", $string);
-Andrei
* On the keyboard of life, always keep one finger on the escape key. *