tags:

views:

36

answers:

3

I'm playing around with an idea, and I'm stuck at this one part. I want to read an external HTML page and then extract the data held within two <dd> tags. I've been using file_get_contents with good results, but I'm at a loss as to how to accomplish that last part. The two tags I want to extract the value from are always enclosed within a particular <div>, was wondering if that might help?

In my mind it reads the entire html file into a string, then dumps all the data up until this one particular <div>, and dumps all the data after the closing </div>. Is that possible? I think this needs regex syntax which I've never used yet. So any tips, links, or examples would be great! I can provide more info as necessary.

A: 

You are complicating way too much. Simply load the page content and then search for the proper regex (preg_match()). This will do fine

preg_match('~<tag id="foobar">(?P<content>.*?)</endtag>~is', $input, $matches);
Mikulas Dite
Yes, you could use RegEx to parse HTML, [or not](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)
hemp
Everybody knows that html is nonregular language. But the question in fact was: I have a text wrapped with some static phrases, how do I find it? Dom is much slower (and in php is even worse than in other languages) than simple regex.
Mikulas Dite
+1  A: 

Maybe this could help: http://simplehtmldom.sourceforge.net/

Nort
A: 

If you use HTQL COM to query the page, the query is: <dd>1:tx

seagulf