0

I am trying to parse a html document and get a particular data out of it and save it into mysql table. But I am stuck in one of the scenerios and want help in it,

I have a html document as given below..

<div class="block">
 <div class="author">M.K.jack</div>
 <a href="x.html">maths</a>
 <a href="y.html">science</a>
 <a href="z.html">english</a>

 <div class="author">samuels</div>
 <a href="a.html">maths</a>
 <a href="b.html">science</a>

 <div class="author">edison</div>
 <a href="h.html">maths</a>
 <a href="g.html">science</a>

</div>

Now i want to parse and save it as a table as given below..

**id**     **url**     **title**     **author**
1          x.html      maths         M.K.jack
2          y.html      science       M.K.jack
3          z.html      english       M.K.jack
4          a.html      maths         samuels
5          b.html      science       samuels
6          h.html      maths         edison
7          g.html      science       edison

In this you can see that the author div doesnt enclose the subject, but is there a way to parse in php where i can store the data in this manner.

  • Use DOMDocument or Simple HTML DOM Parser. http://php.net/DOMDocument http://simplehtmldom.sourceforge.net/ – Charlotte Dunois Jul 17 '16 at 21:22
  • @CharlotteDunois thank you for the reply. I did use simple html dom parser but here my problem is not just with parsing, I hope I have explained the problem in the question properly. The problem is here the **a** tag is outside **div** tag but want to store it in the way shown in the table. – Barbara Jones Jul 17 '16 at 21:31

0 Answers0