Re: how to extract part of HTML page



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.
.



Relevant Pages

  • Re: Please help me find my problem !!!
    ... > basic grasp of PHP somewhat quickly, already have a completed login ... extract(), as ... Tom Thackrey www.creative-light.com tom creative light com do NOT send email to jamesbutler@willglen.net ...
    (comp.lang.php)
  • Re: Idea for PHP Enhancement: register_globals_manual
    ... > Your comment says the same thing I'm saying: that using extract has the ... now support all of the super globals in PHP. ... of the superglobal array to play with. ...
    (comp.lang.php)
  • Re: [PHP] extract escaped quoted strings
    ... I have a bit of PHP code that needs to extract some quoted strings, ... but i'd love some elegant PCRE solution that thus-far evades ...
    (php.general)
  • Re: problem compiling php5-filter [Solved]
    ... Hack-style solution: ... might not work of future upgrades of php 2. ... a FRESH install of FBSD 8.0, with the ports updated two days ago. ... php5 did not extract the required pcre.h file. ...
    (comp.unix.bsd.freebsd.misc)
  • Re: ASF - WMA header
    ... >> file-reading using PHP. ... >The duration is written in an unsigned 64-bit integer in the ... position within the first few hundred bytes of the asf. ... If I can find a good way to read the asf header directly to extract ...
    (microsoft.public.windowsmedia.sdk)