Question

Is there any function or way to replace all characters at once?

$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

Solution for me: 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);   
} 
Was it helpful?

Solution

You can use an array... Pass those characters in an array as shown..

$product['name'] = str_replace(array(":",",","*"), "", $product['name']);

OTHER TIPS

$replace = array(':','*','#','@',......);
$product['name'] = str_replace( $replace , "", $product['name'])

Try this

$product['name'] = utf8_decode(strtolower( strip_tags( $child->name ) ) );
$blacklist=array(':','*','#','@','(',')');//etc etc
$product['name'] = str_replace( $blacklist , "", $product['name']);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top