Leoshen's Blog

php xpath方法查询xml

2018-02-05   php,

<!--markdown-->假定我们有个123.xml文件,代码如下:

$dom = new DOMDocument('1.0','utf-8');
$dom->load('123.xml');
$xpath = new DOMXPath($dom);
$sql = '/test/str[name="'.$str.'"]';
$wordList = $xpath->query($sql);
if($wordList->length === 0){
echo "not found";
提交

评论接口维护中,暂时无法使用...