[英]Simple HTML dom css selector not working
參考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的標簽。
但是,這什么也不會返回。
我的代碼有什么問題?
請仔細閱讀文檔 ...可用的屬性過濾器為:
+--------------------+----------------------------------------------------------------------------------------+
| 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"]');
您尚未在XPath中引用字體。 find()
調用應為
$lis = $dom->find('[style=~"font-family:symbol"]');
^------------------^---- missing
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.