php - SimpleXMLElement::xpath 不区分数字作为字符串
问题描述
我有带有如下标签的xml:
<tag id="02220">
<tag id="2220">
当我搜索例如:
Xml->xpath('//tag [@id='."2220".']');
结果将是两个 id 的数组。如何让 xpath 将它们视为字符串?
解决方案
You will need to include the quotes around the value you are looking for, currently your query comes out as
echo '//tag[@id='."2220".']';
gives
//tag[@id=2220]
as you can see, it is a number. Add quotes round the field...
echo '//tag[@id="'."2220".'"]';
will give you
//tag[@id="2220"]
推荐阅读
- javascript - How to display the value of a javascript variable in html?
- go - AES CTR failing test vectors (except for one)
- visual-studio-code - VSCode dynamic processid in launch.json
- html - SVG 图像作为图案 - 全宽 - 保持比例
- php - Symfony FormType at least one radio selected
- html - 日期输入中的不变日期
- hadoop - Hive 分区验证
- c# - 从下到上对 ItemsControl 进行排序
- c# - 将列表序列化/反序列化为 JSON
- excel - 如何更改数组中的数据在工作表中的显示方式