×

Notice

The forum is in read only mode.

How do you parse and process HTML/XML in PHP and extract information from it?

More
2 months 3 weeks ago #3478 by Elias Katsaniotis,MSc
How do you parse and process HTML/XML in PHP and extract information from it?
More
2 months 3 weeks ago #3479 by Elias Katsaniotis,MSc
see the article/answerHow do you parse and process HTML/XML in PHP?How can one parse HTML/XML and extract information from it? stackoverflow.com/questions/3577641/how-...cess-html-xml-in-phpHow to modify HTML elements:// Create DOM from string 
  • $html = str_get_html('<div id="hello">Hello</div><div id="world">World</div>'); 
  • $html->find('div', 1)->class = 'bar'; 
  • $html->find('div[id=hello]', 0)->innertext = 'foo'; 
  • echo $html; 
    Extract content from HTML:// Dump contents (without tags) from HTML echo file_get_html('www.google.com/')->plaintext; 
      How to get HTML elements: 
       
      • // Create DOM from URL or file 
      •  
      • // Find all images 
      • foreach($html->find('img') as $element) 
      • echo $element->src . '<br>'; 
      •  
      • // Find all links 
      • foreach($html->find('a') as $element) 
      • echo $element->href . '<br>'; 
      Time to create page: 0.172 seconds

      Site Info

      V. Katsanioti,

      Russia,

      Kaliningrad Oblast.

      matizegr@yahoo.com

      Visit counter

      United States of America (the) 80.6% United States of America (the)
      Russian Federation (the) 11.1% Russian Federation (the)
      China 4.9% China

      Total:

      33

      Countries
      00001847
      Today: 17
      Yesterday: 55
      This Week: 72
      Last Week: 565
      This Month: 1,767
      Last Month: 81

      Who's Online

      We have 674 guests and no members online