是否有任何功能或方法可以立即替换所有字符?
$product['name'] = utf8_decode(strtolower( strip_tags( $child->name ) ) );
$product['name'] = str_replace(":", "-", $product['name']);
$product['name'] = str_replace("*", "", $product['name']);
$product['name'] = str_replace("#", "--", $product['name']);
$product['name'] = str_replace("@", "", $product['name']);
$product['name'] = str_replace("(", "---", $product['name']);
$product['name'] = str_replace(")", "", $product['name']);
etc
etc
我的解决方案: http://www.php.net/manual/en/function.str-replace.php#95198
function strReplaceAssoc(array $replace, $product) {
return str_replace(array_keys($replace), array_values($replace), $product);
}
答案 0 :(得分:2)
您可以使用数组...如图所示,将这些字符传递给数组。
$product['name'] = str_replace(array(":",",","*"), "", $product['name']);
答案 1 :(得分:1)
$replace = array(':','*','#','@',......);
$product['name'] = str_replace( $replace , "", $product['name'])
答案 2 :(得分:0)
试试这个
$product['name'] = utf8_decode(strtolower( strip_tags( $child->name ) ) );
$blacklist=array(':','*','#','@','(',')');//etc etc
$product['name'] = str_replace( $blacklist , "", $product['name']);