关于http://simplehtmldom.sourceforge.net/
我有以下代码:
require_once('simple_html_dom.php');
$x = '<span style="font-family:symbol">®</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"]');