是否有任何函數或方法可以一次替換所有字符?Str_replace函數特殊字符
$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);
}
str_replace函數接受數組參數,請查看文檔 – mesutozer