php - How to get only email value from HTML files using DOM ? Only Email value not like link -


http://www.frosher.com/schools/acme-academy-burdwan/contact

this page link saved in folder , address contact information of school. seen email , web link before google map block. want email value.

just save html page in scrapping folder. here's code:

<?php  include('simple_html_dom.php');//required $i = 0;  $dir = 'scrapping/';//folder name in html file if ($handle = opendir($dir)) {     while (($file = readdir($handle)) !== false){         if (!in_array($file, array('.', '..')) && !is_dir($dir.$file))              $i++;     } } $filenames = array(); foreach(glob('scrapping/*.*') $filename){     $filenames[] = $filename;//get files name in folder } $i = 1; foreach($filenames $val){     $doc = new domdocument();     $doc  = file_get_html($val);     $ret = $doc->find('div[class=span5]');      foreach($doc->find('.span7') $element){         $contact = $element->plaintext;              if (preg_match("/\bemail\b/i", $contact, $match)) {             $n = 0; // have used $n counting because in span7 div 2 tag need first time value.             foreach($doc->find('.span7 a') $element){                 if($n == 0){                                         $email = $element;                      $n = $n+1;                 }                                }                    }         else{             $email = 'null';         }                    echo $email;      }            echo '<br/>'; } ?> 

this php script code save file name , place both php file , scrapping folder in common folder leo folder in php file placed , scrapping folder in it.

now run php file , see output. if not have include "simple_html_dom.php" in leo folder.

if getting whole tag try following

  foreach($doc->find('.span7 a') $element){          $email = $element;      $email = strip_tags($email);     //now can check email } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -