2010-02-06 54 views

回答

3

SimpleHTMLDom不在選擇器中使用帶引號的字符串文字。這只是elem[attr=value]。並且的比較似乎區分大小寫(可能有一種方法可以使其不區分大小寫,但我不知道)*

例如,

require 'simple_html_dom.php'; 
$html = file_get_html('http://www.google.com/'); 
// most likely one one element but foreach doesn't hurt 
foreach($html->find('meta[http-equiv=content-type]') as $ct) { 
    echo $ct->content, "\n"; 
} 

打印text/html; charset=ISO-8859-1

*編輯:是的,有執行不區分大小寫的匹配方式,使用的*=代替=

find('meta[http-equiv*=content-type]') 

EDIT2:順便說一句的是http-equiv*=content-type啄也符合<meta http-equiv="haha-no-content-types"...(它只有在字符串測試在屬性值中的某處)。但它是我能找到的唯一不區分大小寫的函數/運算符。我猜你可以在這種情況下使用它;-)
編輯3:它使用preg_match('.../i'),模式/選擇器直接傳遞給該函數。因此你可以做一些像http-equiv*=^content-type$匹配http-equiv="Content-type"但不是http-equiv="xyzContent-typeabc"。但我不知道這是否是一項保證功能。

+0

謝謝,我會過得很愉快! – user198729 2010-02-06 16:31:59

0

Content-Type通常是http-response頭的一部分 - 不在主體中。你從哪裏得到xml文件?

+0

正確來自'file_get_html' – user198729 2010-02-06 16:06:38

0

我會去foreach$this->find('meta');在不同的情況下寫content-type - 我認爲瀏覽器是不是這種情況下敏感,而php可能是。