Is this what you are looking for?
You can try SimpleHTMLDOM . Then you can run something like ...
$html = new simple_html_dom(); $html->load_file('fileToParse.html'); $count=0; foreach($html->find('fb:like') as $element){ $count+=1 } echo $count;
That should work.
I looked a little further and found this. I took this from a DOMDocument on PHP.net.
$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; }
After that i got stuck
$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);
It is, however, RegEx and rather slow. I tried:
$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');
But I got the same error as you.
Bonzo
source share