Php 简单HTML dom css选择器不工作

Php 简单HTML dom css选择器不工作,php,css,dom,css-selectors,simple-html-dom,Php,Css,Dom,Css Selectors,Simple Html Dom,关于 我有以下代码: require_once('simple_html_dom.php'); $x = '<span style="font-family:symbol">&#174;</span>'; $dom = str_get_html($x); $lis = $dom->find('[style=~font-family:symbol]'); print_r($lis); require_once('simple_html_dom.php');

关于

我有以下代码:

require_once('simple_html_dom.php');

$x = '<span style="font-family:symbol">&#174;</span>';
$dom = str_get_html($x);
$lis = $dom->find('[style=~font-family:symbol]');
print_r($lis);
require_once('simple_html_dom.php');
$x='®;';
$dom=str\u get\u html($x);
$lis=$dom->find(“[style=~font-family:symbol]”);
印刷费($lis);
它尝试使用css选择器查找样式中包含字体系列:符号的标记

然而,这不会返回任何结果


我的代码有什么问题

您还没有在XPath中引用字体。
find()
调用应该是

$lis = $dom->find('[style=~"font-family:symbol"]');
                           ^------------------^---- missing
请仔细阅读。。。可用的属性过滤器包括:

+--------------------+----------------------------------------------------------------------------------------+
|       Filter       |                                      Description                                       |
+--------------------+----------------------------------------------------------------------------------------+
| [attribute]        | Matches elements that have the specified attribute.                                    |
| [!attribute]       | Matches elements that don't have the specified attribute.                              |
| [attribute=value]  | Matches elements that have the specified attribute with a certain value.               |
| [attribute!=value] | Matches elements that don't have the specified attribute with a certain value.         |
| [attribute^=value] | Matches elements that have the specified attribute and it starts with a certain value. |
| [attribute$=value] | Matches elements that have the specified attribute and it ends with a certain value.   |
| [attribute*=value] | Matches elements that have the specified attribute and it contains a certain value.    |
+--------------------+----------------------------------------------------------------------------------------+
因此,在您的情况下,您可以使用最后一个示例[以下内容经过测试,并且有效]:

$lis = $dom->find('[style*="font-family:symbol"]');

虽然这根本不能回答这个问题,但使用CSS类比使用内联样式更好……嗯,我尝试了$dom->find(“[style=~”font-family:symbol”]”);而且还是一无所获。因此它实际上不支持
~=
选择器(同时支持一些非标准选择器,如
[!attribute]
!=
)。真奇怪。平心而论,简单HTML DOM的文档糟透了——在再次查看文档后,我仍然不知道您在哪里找到了这个表。@BoltClock
如何找到HTML元素?
属性过滤器