2.4k questions

2.4k answers

96.1k users

8 Online Users
2 Member 6 Guest
Online Members
Today Visits : 1902
Yesterday Visits : 2089
Total Visits : 2362324

Categories

Notice

Dear All, These are my answers from Quora and primarily Google; please check the answer and from others sites; the answers are free and without any liability.To make a decision, write down all of the positives and negatives on a piece of paper.Thank you,

Elias Katsaniotis, MSc

Information

Viktoria Katsanioti,

Kaliningrad,

Russia,

matizegr@yahoo.com

0 votes
50 views

How do you parse and process HTML/XML in PHP and extract information from it?
in General by (95.8k points)

1 Answer

0 votes

see the article/answer

How do you parse and process HTML/XML in PHP?

How can one parse HTML/XML and extract information from it?

https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php

How 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('http://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>'; 
        by (95.8k points)
        ...