How parse html in php?

I know we can use PHP DOM to parse HTML using PHP. I found a lot of questions here on Stack Overflow too. But I have a specific requirement. I have an HTML content like below

Chapter 1

This is chapter 1

Chapter 2

This is chapter 2

Chapter 3

This is chapter 3

I want to parse the above HTML and save the content into two different arrays like:

$heading and $content

$heading = array['Chapter 1','Chapter 2','Chapter 3'];
$content = array['This is chapter 1','This is chapter 2','This is chapter 3'];

I can achieve this simply using jQuery. But I am not sure, if that's the right way. It would be great if someone can point me to the right direction. Thanks in advance.

hatef

4,60328 gold badges44 silver badges43 bronze badges

asked Aug 21, 2013 at 4:55

6

I have used domdocument and domxpath to get the solution, you can find it at:

Chủ Đề