Remove Multiple word From a string in comma separated String.
<?php
function removeFromString($str, $item) {
    $parts = explode(',', $str);
    while(($i = array_search($item, $parts)) !== false) {
        unset($parts[$i]);
    }
    return implode(',', $parts);
}
$arra ="one,two";
$string ='one,two,three,four';
$array =explode(",",$arra);
foreach($array as $key=>$value)
{
 $string= removeFromString($string, $value);
}
echo $string;
?>
OutPut: three,four
Comments
Post a Comment