note 40726 modified in function.strpos by aidan
| From: | aidan@php.net | Date: | Thu, 10 Jun 2004 06:57:06 +0000 |
| Subject: | note 40726 modified in function.strpos by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-70811@lists.php.net to get a copy of this message | ||
Here is an example of removal illegal symbols from string in array. It works much faster than code
with regexp usage:
<?php
$text='This $tring cont@in$ ## of i\\lega\\ symb*ls';
$illegal=array('@',"$",'^','*','#','\\\\',':',';','<','>');
$garb=array();
foreach($illegal as $k) while(($j=strpos($text,$k))!==false){$garb[]=$text{$j};
$text=substr($text,0,$j).substr($text,$j+1);}
$garb=array_unique($garb);
?>
after that $text will contain "This tring contin s of ilega symbls" and in $garb there
will be @$*#\\ symbols.
--was--
Here is an example of removal illegal symbols from string in array. It works much faster than code
with regexp usage:
$text='This $tring cont@in$ ## of i\\lega\\ symb*ls';
$illegal=array('@',"$",'^','*','#','\\\\',':',';','<','>');
$garb=array();
foreach($illegal as $k) while(($j=strpos($text,$k))!==false){$garb[]=$text{$j};
$text=substr($text,0,$j).substr($text,$j+1);}
$garb=array_unique($garb);
after that $text will contain "This tring contin s of ilega symbls" and in $garb there
will be @$*#\\ symbols.
http://www.php.net/manual/en/function.strpos.php