【问题标题】:SimpleXMLElement::xpath dont diferintiate between number as stringSimpleXMLElement::xpath 不区分数字作为字符串
【发布时间】:2020-10-13 14:56:04
【问题描述】:

我有如下标签的xml:

<tag id="02220">
<tag id="2220">

当我在以下位置搜索示例时:

Xml->xpath('//tag [@id='."2220".']');

结果将是一个包含两个 id 的数组。如何让 xpath 把它们当作字符串处理?

【问题讨论】:

    标签: php xml xpath


    【解决方案1】:

    您需要在要查找的值周围加上引号,目前您的查询结果为

    echo '//tag[@id='."2220".']';
    

    给予

    //tag[@id=2220]
    

    如您所见,它是一个数字。在字段周围添加引号...

    echo '//tag[@id="'."2220".'"]';
    

    会给你

    //tag[@id="2220"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2016-09-21
      • 1970-01-01
      相关资源
      最近更新 更多