$item
has a /
in it, which means that it thinks that the regex ends sooner than it does.
/goldfish/herring/
// ^ Not actually a modifier (h) - just an unescaped string
You can use the preg_quote($string, '/')
function for this to turn it into the following:
/goldfish\/herring/
// ^ Escaped
Usage:
foreach($items as $k=>$item){
if($item!='' && preg_match("/".preg_quote($item,"/")."/", $opText)){
if(!in_array($item,$params[$val['name']],true)){
$params[$val['name']][]=$item;
}
}
}
Tip:
If this is a hardcoded regex, you can change your escape character to make the regex easier to read by not having to escape a commonly used character:
~goldfish/herring~
// ^ ^
// | \- Using a different modifier
// |
// \- Different from the modifier, so we don't have to escape it