When the input string contains a "/" symbol, I'm getting a PHP error:
Warning: preg_match() [function.preg-match]: Unknown modifier
How can I resolve it?
$token = '/<'.$tag.'[^>]*>(.*\b'.$keyword.'\b.*)<\/'.$tag.'>/siU';
if(preg_match($token, &$content, $matches))
{
$match = 1;
}
return $match;
You should use preg_quote() to escape tag and keyword, like this:
$token = '/<' . preg_quote($tag, '/') . '[^>]*>(.*\b' . preg_quote($keyword, '/')
. '\b.*)<\/' . preg_quote($tag, '/') . '>/siU';
preg_quote function should help you with this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With