Odd search error. . .
Permalink
Hello all,
When I use the search feature, it works great.
However, if I search for something that has a "#" sign in it, which some products I'm listing do, I get an error.
It only seems to kick in when the # sign is in the search. If I just search for "#", I get this error:
However, if I search for something like "Number #1", it's fine. If I search for "Number #2", I get the error—it only happens if I have "#2" in there. If I separate them w/ a space "Number # 2", it's fine too, just something w/ "#2" in it makes the error. But "Number 2", "Number #22" and "Number # 2" all work.
"Number #2" search gives the following error:
So it appears something about "#2" affects the regex.
Any ideas out there as to what might cause this? Normally, it wouldn't be a big deal, but since I do have products that have "#2" in their name, I'd better look into fixing it just in case.
I'm using c5.5.2.1, and the line it keeps referring to in the search block is:
Thanks in advance!
When I use the search feature, it works great.
However, if I search for something that has a "#" sign in it, which some products I'm listing do, I get an error.
It only seems to kick in when the # sign is in the search. If I just search for "#", I get this error:
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '(' in /path/to/site/blocks/search/controller.php on line 35
However, if I search for something like "Number #1", it's fine. If I search for "Number #2", I get the error—it only happens if I have "#2" in there. If I separate them w/ a space "Number # 2", it's fine too, just something w/ "#2" in it makes the error. But "Number 2", "Number #22" and "Number # 2" all work.
"Number #2" search gives the following error:
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier '2' in /path/to/site/blocks/search/controller.php on line 35
So it appears something about "#2" affects the regex.
Any ideas out there as to what might cause this? Normally, it wouldn't be a big deal, but since I do have products that have "#2" in their name, I'd better look into fixing it just in case.
I'm using c5.5.2.1, and the line it keeps referring to in the search block is:
preg_match_all("#$regex#ui", $text, $matches);
Thanks in advance!
The 'ui' on the end are modifiers to make it case agnostic and unicode compatible.
You could try replacing "#$regex#ui" with "/".$regex."/ui" . In which case '/' becomes the delimiter, so would need to be escaped with '\' if it appeared within the text of $regex.
Another commonly used regex delimiter is '{..}', so you could also code it as "{".$regex."}ui". Same notes as above about escaping.