HaiZone HaiZone - 1 month ago 5
PHP Question

Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 22

i'm trying to change the preg_match check from url checking and i'm getting this error


Blockquote
preg_match_all(): Compilation failed: nothing to repeat at offset 22


this is the code:

preg_match_all('#\b(' . $allWordsFromProduct . ')\b#ui', $name, $matches);

Answer

May $allWordsFromProduct contains special regex character. You can try:

 $allWordsFromProduct = preg_quote($allWordsFromProduct , '#');
 preg_match_all('#\b(' . $allWordsFromProduct . ')\b#ui', $name, $matches);

This will escape them.

Comments