我正试图为我的新网站开发一个导航面包屑系统。我的页面使用SimpleXML从xml数据库中检索它的文件名和页面信息。
我收到preg_replace()的php错误 最后一个代码块中的函数:分析错误:语法错误,第21行/home/content/85/8762385/html/joelsdesign/moiles/we-are-hiring.php中的意外T_STRING
在文件的标题中,有$dom=simplexml_load_file('pages.xml')
这是我的xml文件的内容:http://joelsdesign.info/movies/scores.xml
我的导航菜单是"必需的",require语句存储在名为$nav的变量中
foreach ($dom->page as $page) {
$title = $page->title;
$file = $page->file;
$nav = file_get_contents('require/nav.php');
$nav = preg_replace("<li><a href='"".$file."'">".$title."</a></li>", "<li class="current"><a href='"".$file."'">".$title."</a></li>", $nav);
}
单词current
周围的引号未转义:
$nav = preg_replace("<li><a href='"".$file."'">".$title."</a></li>", "<li class='"current'"><a href='"".$file."'">".$title."</a></li>", $nav);
此外,您不应该在不使用regex的情况下使用preg_replace。您应该使用str_replace。
如果你真的需要preg_replace,你应该写一个正则表达式,它需要以分隔符开头,通常是正斜杠/
。因此,第二个错误是由于<
不是正则表达式的已知分隔符而造成的。