note 50454 modified in function.ord by danbrown

From: Date: Tue, 11 Oct 2011 16:15:37 +0000
Subject: note 50454 modified in function.ord by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183807@lists.php.net to get a copy of this message
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; } ?> --was-- 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.. <? 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; } ?> http://php.net/manual/en/function.ord.php

« previous php.notes (#183807) next »