PHP DOM Xpath - 搜索类名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8680721/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP DOM Xpath - search for class name
提问by yoda
Possible Duplicate:
XPath: How to match attributes that contain a certain string
可能的重复:
XPath:如何匹配包含特定字符串的属性
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
我正在尝试使用 PHP DOM Xpath 解析一些 html,但是当元素有多个时,我在搜索类名时遇到问题。我发现如果我使用像这样的孔属性值
$xpath->query('//div[@class="precodet precodeturgente"]');
it works, but if I do
它有效,但如果我这样做
$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.
它不会给我节点值。有时只有一个班级,而其他班级不止一个,所以我想知道是否有办法搜索单个班级名称。
回答by eagle12
You should be able to do
你应该能够做到
$xpath->query('//div[contains(@class,"precodet")]');