gpt4 book ai didi

php - 简单的 HTML dom css 选择器不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 13:37:07 25 4
gpt4 key购买 nike

引用http://simplehtmldom.sourceforge.net/

我有这个代码:

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);

它尝试使用 css 选择器查找其样式中包含 font-family:symbol 的标签。

然而,这没有任何返回。

我的代码有什么问题?

最佳答案

请阅读the doc仔细...可用的属性过滤器是:

+--------------------+----------------------------------------------------------------------------------------+
| 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"]');

关于php - 简单的 HTML dom css 选择器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22968658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com