PHP Warning: preg_match () [duplicate]

0

follow the code:

$ER = '[\/]?([?]?pag=[a-zA-Z0-9_-]*)(&var1=[a-zA-Z0-9_-]*)?(&var2=[a-zA-Z0-9_-]*)?(&var3=[a-zA-Z0-9_-]*)?(&var4=[a-zA-Z0-9_-]*)?'; // A ER que separa as vars
$wURL = W_URL;
$http = 'http://';
if( $https || $_SERVER["SERVER_PORT"] != 80 ){
    $url_site =  str_replace('http:', 'https:', URL_SITE);
}else{
    $url_site =  URL_SITE;
}
$_save_pag = '';
//Executa o rewrite somente quando estiver definido para tal
if($doRewrite == true){

    if(empty($str) && preg_match($ER,$str,$registers)){

error:

  

PHP Warning: preg_match (): Unknown modifier '?' in /home/sisv2/sis_adm/includes/funcoes/rewrite.func.php on line 17

    
asked by anonymous 16.03.2015 / 17:13

1 answer

0

This error is occurring because your expression should be delimited by '/' or '#'.

Soon, it would look like this:

$ER = '/[\/]?([?]?pag=[a-zA-Z0-9_-]*)(&var1=[a-zA-Z0-9_-]*)?(&var2=[a-zA-Z0-9_-]*)?(&var3=[a-zA-Z0-9_-]*)?(&var4=[a-zA-Z0-9_-]*)?/'; // A ER que separa as vars

This is because when you specify options for your regular expression (multi-line, single line, case sensitive etc.), they are "out" of the expression after the second delimiter. >     

16.03.2015 / 17:25