function replaceItems($value) {
$found = false;
$patterns = array('/T-Shirt, Top/',
'/Shirt, Polo/');
$replacements = array('Clothing > Tops & T-Shirts',
'Clothing > Shirts');
$result = preg_replace($patterns, $replacements, $value);
if($result != $value){
//preg_replace returns the changed string if anything was
//changed so here I check if the string is different from the original
$found = true;
}
return ($found) ? $result : "";
}
echo replaceItems("lorem ipsum, T-Shirt, Top lorem ipsumother test");
//returns 'rem ipsum, Clothing > Tops & T-Shirts lorem ipsumother test'
Put the words you want to replace in the $patterns array and the replacements in the replacements array. Just make sure they are on the same key.