PHP DOM Xpath - 搜索类名 [英] PHP DOM Xpath - search for class name

查看:69
本文介绍了PHP DOM Xpath - 搜索类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

XPath:如何匹配包含某个字符串的属性

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

I'm trying to parse some html with PHP DOM Xpath, but I'm having problems searching for a class name when the element has more than one. I found that if I use the hole attribute value like

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

它有效,但如果我做

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

它不会给我节点值。有时候只有一个班,其他有一班,所以我想知道的是如果有办法搜索一个单一的名字。

it won't give me the node value. Sometimes there's only one class, others there are more than one, so what I want to know is if there's a way to search for a single class name.

推荐答案

您应该可以执行

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

这篇关于PHP DOM Xpath - 搜索类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆