PHP: Do NOT rebuild preg_* functions!
In a PHP Project i am currently helping out, i found this function:
/**
* Replaces every char in $str that does is not in $valid array
*
* @param array $valid
* @param string $str
* @return string
*/
function cleanString($valid, $str) {
$ret = '';
$len = strlen($str);
for($i = 0; $i < $len; ++$i) {
if(in_array($str[$i], $valid, true)) {
$ret .= $str[$i];
}
}
return $ret;
}
* Replaces every char in $str that does is not in $valid array
*
* @param array $valid
* @param string $str
* @return string
*/
function cleanString($valid, $str) {
$ret = '';
$len = strlen($str);
for($i = 0; $i < $len; ++$i) {
if(in_array($str[$i], $valid, true)) {
$ret .= $str[$i];
}
}
return $ret;
}
It is a simple function for replacing chars. It works quite well, but was mainly only used for checking [^a-z0-9]. So i tested the speed of this code.
Den ganzen Beitrag lesen...