我有以下XML
$xml = <<<XML
<books>
<book>
<title>PHP Basic's</title>
<author>Jim Smith</author>
<author>Jane Smith</author>
</book>
<book>
<title>PHP Secrets</title>
<author>Jenny Smythe</author>
</book>
<book>
<title>XML basics</title>
<author>Joe Black</author>
</book>
</books>
XML;
遵循PHP代码
$xml = simplexml_load_string($xml);
$books = $xml->xpath("//book[contains(title,'Basic's')]");
问题是:如何搜索带撇号的字符串?我尝试使用like尝试用Single(')和Double(“)引用整个XPATH表达式,但无法创建正确的XPATH表达式。任何人都可以帮助我吗?
答案 0 :(得分:1)
您可以使用'
切换"
并转义Basic's
中的撇号:
$books = $xml->xpath('//book[contains(title,"Basic\'s")]');