2012-06-17 89 views
0

請幫忙。我得到這個錯誤:preg_match錯誤和調試php代碼

(!) Warning: preg_match(): Unknown modifier 'b' in C:\wamp\www\pmd\install\ioncube_checker.php on line 22

當我運行下面的代碼:

function system_info($php_info) { 
$server_info = array(); 
$server_info['thread_safe'] = 'false'; 
$server_info['debug_build'] = 'false'; 
$server_info['php_ini_path'] = ''; 

foreach (explode("\n",$php_info) as $line) { 
    if (preg_match('/command/',$line)) { 
     continue; 
    } 

    if (preg_match('/thread safety.*(enabled|yes)/Ui',$line)) { 
     $server_info['thread_safe'] = 'true'; 
    } 

    if (preg_match('/debug.*(enabled|yes)/Ui',$line)) { 
     $server_info['debug_build'] = 'true'; 
    } 


    if (preg_match("/configuration file.*(</b></td><TD ALIGN=\"left\">| => |v\">)([^ <]*)(.*</td>*)?/",$line,$match)) { 
     $server_info['php_ini_path'] = $match[2]; 

     if ([email protected]_exists($php_ini_path)) { 
      $server_info['php_ini_path'] = ''; 
     } 
    } 

    $cgi_cli = ((strpos(php_sapi_name(),'cgi') !== false) || (strpos(php_sapi_name(),'cli') !== false)); 
    $cgi_cli ? $server_info['cgi_cli'] = 'true' : $server_info['cgi_cli'] = 'false'; 
} 
return $server_info; 

}

回答

1

由於您使用/爲正則表達式的分隔符,你需要逃避與任何/\。然而,它更容易使用與HTM打交道時,不同的分隔符:

preg_match("/configuration file.*(</b></td><TD ALIGN=\"left\">| => |v\">)([^ <]*)(.*</td>*)?/",$line,$match) 

應該

preg_match("#configuration file.*(</b></td><TD ALIGN=\"left\">| => |v\">)([^ <]*)(.*</td>*)?#",$line,$match) 

但是,你應該考慮not using regexes to parse HTML at all - 使用DOM引擎是多少變得更好,和PHP已經has one