Page 1 of 1

[SOLVED] Parsing some HTML Code??

Posted: Sat Mar 10, 2007 6:57 pm
by matth2004
Hi,

I've pulled some code from a website (with permission) and I need to extract the HTML between two tags I've chosen. I need to get all code between the start tag:

Code: Select all

<td bgcolor="#ffffff"><div class="h1">
And the end tag:

Code: Select all

</tr><tr><td><img src="webi/space.gif" width="1" height="20" alt="">
Any idea how I would go about doing this? BTW I don't know any Regex.

Regards,
Matt

Posted: Sat Mar 10, 2007 7:00 pm
by feyd

Posted: Sat Mar 10, 2007 7:11 pm
by matth2004
I tried them and used this code:

Code: Select all

$pos = strpos($pagesource, "<td bgcolor=\"#ffffff\"><div class=\"h1\">");
$pos2 = strpos($pagesource, "</tr><tr><td><img src=\"webi/space.gif\" width=\"1\" height=\"20\" alt=\"\">");
$posmath = $pos2-$pos;
$ladder = substr($pagesource, $pos, $posmath);
But it displays the whole page...

Regards,
Matt

Posted: Sat Mar 10, 2007 7:16 pm
by feyd

Code: Select all

$one = "<td bgcolor=\"#ffffff\"><div class=\"h1\">";
$two = "</tr><tr><td><img src=\"webi/space.gif\" width=\"1\" height=\"20\" alt=\"\">";
$pos = strpos($pagesource, $one) + strlen($one);
$pos2 = strpos($pagesource, $two);
$posmath = $pos2 - $pos;
$ladder = substr($pagesource, $pos , $posmath);
var_dump($ladder);
:?:

Posted: Sat Mar 10, 2007 7:16 pm
by matth2004
Don't worry, all fixed, it was picky about the uppercase of the color code. Thanks heaps for your help.

Regards,
Matt