当主机更新php版本时,我的网站显示以下错误
警告:preg_match():在
中找不到结尾分隔符'^'在以下代码中:
<?php
$mid_str = " and mid != '0' and ";
if($_REQUEST['search']){
mysql_select_db($database_myconn, $myconn);
$query_spages = "SELECT id, url, title, description, keywords, active, ip, catID, exp, pdate,
MATCH(title,description,keywords)
AGAINST ('$search_str' IN BOOLEAN MODE) AS score FROM pages
WHERE MATCH(title, description,keywords)
AGAINST ('$search_str' IN BOOLEAN MODE) " . $mid_str . " active = 'Yes' ORDER BY score DESC";
}else// not search fetch rand by catid
$query_spages = "SELECT * FROM pages where " . preg_match("^ and", "", $mid_str) . " active = 'Yes' and catID = '" . $_REQUEST['id'] . "' ORDER BY mid DESC";
mysql_select_db($database_myconn, $myconn);
$spages = mysql_query($query_spages, $myconn) or die(mysql_error());
//$row_spages = mysql_fetch_assoc($spages);
unset($settings);
$settings = mysql_fetch_assoc(mysql_query('select * from settings where id = 1',$myconn));
?>
答案 0 :(得分:1)
preg_match期望正则表达式的开始和结束。
例如preg_match("/^ and/", "", $mid_str)
。
在您的情况下,^
被视为起始分隔符,但正则表达式不以^
结束,因此您收到错误。开始和结束分隔符可以是任何内容,但很可能/
用于不与其他特殊处理的字符冲突。
此外,您可能混淆了preg_match
和preg_replace
。我想你想preg_replace
在这里,p.e。
$query_spages = "SELECT * FROM pages where " . preg_replace("/^ and/", "", $mid_str) . " active = 'Yes' and catID = '" . $_REQUEST['id'] . "' ORDER BY mid DESC";