I would like to make a simple but non trivial manipulation of DOM Elements with PHP but I am lost.
Assume a page like Wikipedia where you have paragraphs and titles (<p>
, <h2>
). They are siblings. I would like to take both elements, in sequential order.
I have tried GetElementbyName
but then you have no possibility to organize information.
I have tried DOMXPath->query()
but I found it really confusing.
Just parsing something like:
<html>
<head></head>
<body>
<h2>Title1</h2>
<p>Paragraph1</p>
<p>Paragraph2</p>
<h2>Title2</h2>
<p>Paragraph3</p>
</body>
</html>
into:
Title1 Paragraph1 Paragraph2 Title2 Paragraph3
With a few bits of HTML code I do not need between all.
Thank you. I hope question does not look like homework.