Re: how to extract part of HTML page
- From: r0g <aioe.org@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 16 Sep 2008 10:32:37 -0400
Ecka wrote:
Hi everyone,
I'm trying to write a PHP script that connects to a bank's currency
convertor page using cURL and that part works fine. The issue is that I
end up with a page that includes a lot of information that I don't
need. Using the PHP function strip_tags I've ended with the text below
and from the remaining HTML code, I'd like to extract the lines starting
with "<TABLE BORDER="1" WIDTH="315">" up to its closing </TABLE> tag.
How do I do this using PHP? I tried using preg_match and the like but
my regex skills are pretty bad. Not too sure where to start. Could
someone please provide me with some pointers?
=========================================================================================
<TABLE BORDER="0" WIDTH="600">
<tr>
<td width="148"></td>
<td width="448">some text some text some text some text some text</td>
</tr>
</TABLE>
<TABLE BORDER="0" WIDTH="600">
<TR><TD VALIGN="top" WIDTH="148">
</TD>
<TD WIDTH="448" VALIGN="top">
<TABLE BORDER="0" WIDTH="448">
<TR><TD>
some text some text some text some text some text some text some text
some text some text some text.
some text some text some text some text some text
</TD></TR>
<TR><TD>
<TABLE BORDER="1" WIDTH="315"> <-----
extract from here
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
<TR><TD>
some text some text some text some text
some text
</TD>
<TD ALIGN="right">
some text some text some text some text
some text
</TD></TR>
</TABLE> <--------- to here
</TD></TR>
<TR><TD>
a {
color:blue;
}
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text
</TD></TR>
<TR><TD>
some text some text some text some text some text
some text some text some text some text some text some
text some text some text some text some text some text some
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
<br>
=========================================================================================
Thanks
Eric
Try this.
preg_match('#TABLE BORDER="1"
WIDTH="315">(.*?)?\</TABLE>#s',$source,$result);
print $result[1];
Always start small with regexes and build them up a bit at a time, if
you try and do a complex one all in one go you're asking for trouble!
Regards,
Roger.
.
- Follow-Ups:
- Re: how to extract part of HTML page
- From: Curtis
- Re: how to extract part of HTML page
- References:
- how to extract part of HTML page
- From: Ecka
- how to extract part of HTML page
- Prev by Date: Re: Why does my class require the public accessor for my member?
- Next by Date: Online code editor for beginner's PHP class
- Previous by thread: Re: how to extract part of HTML page
- Next by thread: Re: how to extract part of HTML page
- Index(es):
Relevant Pages
|