Hi I use the file_get_content to grab a webpage (url) and I want to
get the content in some specific tags. <h1> and <h2>
I have read DOM-document is the best way to do this but I’m just not sure
how to use it and most I find on google is for XML… which won’t help me I guess.
So how do I take the content in the <h1> tag from a webpage and store it in a php variable?
Whenever I need to dig through HTML in PHP I use this package:
It makes it easy to load html from a file, url or string, then traverse it using CSS-like selectors. It comes with manual pages and examples, so it’s all pretty simple.
ps: this function will only work for non nested tag… a tag which contains the same tag as child within it will give u wrong result… meaning div tag like tag which can contain a child div tag will give u wrong answer…
if u also need that sort of function which works on nested tag, let me know…
i will try to write that for u…
cheers…