【问题标题】:PHP DOM Xpath - search for class name [duplicate]PHP DOM Xpath - 搜索类名[重复]
【发布时间】:2012-01-30 15:08:05
【问题描述】:

可能重复:
XPath: How to match attributes that contain a certain string

我正在尝试使用 PHP DOM Xpath 解析一些 html,但是当元素有多个时,我在搜索类名时遇到问题。我发现如果我使用hole属性值,比如

$xpath->query('//div[@class="precodet precodeturgente"]'); 

它有效,但如果我这样做

$xpath->query('//div[@class="precodet"]');

它不会给我节点值。有时只有一个类,有些则不止一个,所以我想知道是否有办法搜索单个类名。

【问题讨论】:

    标签: php dom xpath


    【解决方案1】:

    你应该可以的

    $xpath->query('//div[contains(@class,"precodet")]');
    

    【讨论】:

    • 这将匹配任何以 precodet 开头的类,例如 XprecodetY 将被匹配
    • 什么是完全匹配这个类的解决方案,而不是任何其他以“precodet”开头的类?
    猜你喜欢
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 2020-09-06
    • 2017-11-22
    相关资源
    最近更新 更多