Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
现在我有一个看起来像这样的 xpath 搜索功能:
$paragraph = $xmldoc->xpath("//p[contains(., '$wordsearch')]");
我想知道是否有可能 let$wordsearch是一个正则表达式,所以我的搜索看起来像这样:
$wordsearch
$paragraph = $xmldoc->xpath("//p[contains(., '$regularExpression')]");
谢谢你的帮助。
您可以改为使用正则表达式过滤数组:
$paragraph = array_filter( $xmldoc->xpath("//p"), function ($p) use ($regularExpression) { return preg_match($regularExpression, $p); } );
见array_filter。
array_filter