Warning when using preg_match ()

2

I had to migrate from PHP 5.2 to 5.3, so thousands of DEPRECATED messages started coming in my PHP system, but some are too complicated, follow the code:

if (!preg_match($SUBMENU.':', $sm)) {
    $sm = explode($SUBMENU.":\n", $sm);
    $sm = trim(preg_replace('/[^(<ul>)]<\/ul>.*/s', "\1\t</ul>", $sm[1]));
    $sm = str_replace(array('{URL_IMAGENS}', '{URL_SITE}'), array(URL_IMAGENS, URL_SITE), $sm);
    $mainTpl->assign('SUBMENU', $sm, 'STATIC');
}

Then I get the error:

  

Warning: preg_match () [function.preg-match]: Delimiter must not be   alphanumeric or backslash in /home/sisv2/public_html/adm/index.php on   line 135

    
asked by anonymous 16.03.2015 / 01:10

1 answer

2

When using regular expressions in PHP like the preg_match() we should insert an extra delimiter in the our pattern. Your mistake is not to use any delimiters:

if (!preg_match('/' . $SUBMENU .':/', $sm)) 
    
16.03.2015 / 01:23