PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
matth2004
Forum Commoner
Posts: 40 Joined: Wed Sep 06, 2006 3:26 am
Post
by matth2004 » Sat Mar 10, 2007 6:57 pm
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
Last edited by
matth2004 on Sat Mar 10, 2007 7:17 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 10, 2007 7:00 pm
matth2004
Forum Commoner
Posts: 40 Joined: Wed Sep 06, 2006 3:26 am
Post
by matth2004 » Sat Mar 10, 2007 7:11 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Mar 10, 2007 7:16 pm
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);
Last edited by
feyd on Sat Mar 10, 2007 7:17 pm, edited 1 time in total.
matth2004
Forum Commoner
Posts: 40 Joined: Wed Sep 06, 2006 3:26 am
Post
by matth2004 » Sat Mar 10, 2007 7:16 pm
Don't worry, all fixed, it was picky about the uppercase of the color code. Thanks heaps for your help.
Regards,
Matt