note 50454 deleted from function.ord by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 11:39:01 +0000 |
| Subject: | note 50454 deleted from function.ord by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189600@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Function using ord() to strip out garbage characters and punctuation from a string. This is handy
when trying to be smart about what an input is "trying" to be..
<?php
function cleanstr($string){
$len = strlen($string);
for($a=0; $a<$len; $a++){
$p = ord($string[$a]);
# chr(32) is space, it is preserved..
(($p > 64 && $p < 123) || $p == 32) ? $ret .= $string[$a] : $ret .= "";
}
return $ret;
}
?>