I have an array $c=array("ok","and","or")
and a $str="i am ok and fine"
now i want to strip $str from $c array elements so that $str="i am fine"
how can i do this?
There are two things going on here. One is the editing of the string to remove the words you've mentioned. The other is the manipulation of the string to handle it word by word. If you just do character replacement you get extra spaces.
So try something like this. Not debugged.
$q = explode(' ',$str); /* turn string into list of words */
$r = array();
foreach ($q as $w) { /* check the words */
if (!in_array($w,$c)) {
$r[] = $w;
}
}
$str = implode(' ',$r); /* turn new list of words back into string */
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments