zend framework - Zend_Dom_Query to check schema.org markup -
i want check if website contains schema.org markup? doing following:
$domain = 'http://agents.allstate.com/william-leahy-mount-prospect-il.html'; $client = new zend_http_client(); $client->seturi($domain); $response = $client->request(); $html = $response->getbody(); $dom = new zend_dom_query($html); $resultschema = $dom->query('body'); foreach($resultschema $r){ $data = $r->hasattribute('itemprop'); if($data) echo 'yes'; else echo 'no'; }
i not understanding how find this. correct way of doing it? schema.org markup used on website may use html element. how can query elements , find 1 contains schema.org markup?
finally after long search , reading able answer! how done if someone's still looking answer.
$seperator = '|'; $dbdata = ''; $domain = 'http://agents.allstate.com/william-leahy-mount-prospect-il.html'; $client = new zend_http_client(); $client->seturi($domain); $response = $client->request(); $html = $response->getbody(); $dom = new zend_dom_query($html); $result = $dom->queryxpath('//*[@itemtype="http://schema.org/localbusiness"]'); if($result->count()){ foreach ($result $r) { if($r->haschildnodes()) { $lbhtml = $r->c14n(); $dom2 = new zend_dom_query($lbhtml); $lbname = $dom2->queryxpath('//*[@itemprop="name"]'); if($lbname->count()){ foreach ($lbname $name) { $name = $name->nodevalue; } } } } } if(isset($name)) $dbdata .= 'name:'.$name.$seperator; else $dbdata .= 'name:'.$seperator; $result = $dom->queryxpath('//*[@itemtype="http://schema.org/postaladdress"]'); if($result->count()){ foreach ($result $r) { $address = $r->nodevalue; } } if(isset($address)) $dbdata .= 'address:'.$address.$seperator; else $dbdata .= 'address:'.$seperator; $result = $dom->queryxpath('//*[@itemprop="telephone"]'); if($result->count()){ foreach ($result $r) { $telephone = $r->nodevalue; } } if(isset($telephone)) $dbdata .= 'telephone:'.$telephone.$seperator; else $dbdata .= 'telephone:'.$seperator; $dbdata = trim($dbdata,'|');
$dbdata contain string containing properties of schema.org data. hope helps!
Comments
Post a Comment