Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help extracting sections of HTML page

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm new to PHP and need a little guidance on extracting specific sections of a webpage. The sections begin and end with specific HTML tags. And I need to copy everything in between the tags for later processing. But there are two problems. First, the number of "sections" on a page can vary. And second, how to formulate a regular expression that will identify the opening tag, and extract everything between it and the closing tag. For example:

...other HTML

<td align=left valign=middle>
extract
whatever
is
here
<td valign=middle align=center>

...other HTML

<td align=left valign=middle>
extract
whatever
is
here
<td valign=middle align=center>

...other HTML

Any suggestions to get me started would be appreciated.
 
This should help you get started,

$fcontents = file(other.html); // fill with the target file

while (list ($line_num, $line) = each ($fcontents)) {

if (eregi(&quot;^\<td align=left&quot;,$line)) {

echo $line;

}
}

Don't trust my regexp at this timeof nite.. ;-)

Read this:
and related bits about
preg_match
ereg
preg_replace

You'll get it soon enuff :) ***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top