Warning: preg_match() [function.preg-match]

Hi

These are the lines of code getting errors followin is from cs-cart

Code
if ($partial == true) {
$__tmp = str_replace(array(‘‘, ‘?’, ‘/’), array(’.’, ‘.’, ‘\/’), $v);
if (preg_match(“/^$__tmp\$/iu”, $elm)) {
$suitable = true;
break;

Error
“Warning: preg_match() [function.preg-match]: Compilation failed: missing ) at offset 16 in core/fn.locations.php on line 156”

Line 156 is if (preg_match(“/^$__tmp\$/iu”, $elm)) {

Please help stuck here

Let me try what you said and revert

Check http://www.php.net/manual/en/function.preg-match.php for the correct syntax of preg_match.

Saw that but cant understand the issue cause the syntax looks ok

What is the value of $__temp ?

I googled for that error, and it seems that having a ‘(’ in the regex can be a problem. And the solution should be to pass the regex through preg_quote(). Take a look at the manual: http://www.php.net/preg_quote

guido2004 is right. Try the following

if (preg_match('/^' . preg_quote($__tmp, '/') . '$/iu', $elm)) {

if (preg_match(‘/^’ . preg_quote($__tmp, ‘/’) . ‘$/iu’, $elm))

This give me an error Parse error: syntax error, unexpected T_ELSE in /home/homeidea/public_html/mall/core/fn.locations.php on line 160

I forgot the {. Try it now.

U mean use the statement with the {… ok will try the same thanks

Thanks Gvre and guido works perfectly now…