これはあなたが探しているものですか?
SimpleHTMLDOMを試すことができます。次に、次のようなものを実行できます...
$html = new simple_html_dom();
$html->load_file('fileToParse.html');
$count=0;
foreach($html->find('fb:like') as $element){
$count+=1
}
echo $count;
それはうまくいくはずです。
もう少し調べてみると、これが見つかりました。これは、PHP.netのDOMDocumentから取得しました。
$dom = new DOMDocument;
$dom->loadHTML('fileToParse.html'); // or $dom->loadXML('fileToParse.html');
$likes = $dom->getElementsByTagName('fb:like');
$count=0;
foreach ($likes as $like) {
$count+=1;
}
この後私は立ち往生しています
$file=file_get_contents("other.html");
$search = '/<fb:like[^>]*>/';
$count = preg_match_all($search , $file, $matches);
echo $count;
//Below is not needed
print_r($matches);
ただし、これは正規表現であり、非常に低速です。私は試した:
$dom = new DOMDocument;
$xpath = new DOMXPath($dom);
$dom->load("other.html");
$xpath = new DOMXPath($dom);
$rootNamespace = $dom->lookupNamespaceUri($dom->namespaceURI);
$xpath->registerNamespace('fb', $rootNamespace);
$elementList = $xpath->query('//fb:like');
しかし、あなたと同じエラーが発生しました。