Reputation: 61
So I'm trying to grab the href value from an
<a>
from the top image on this url: http://www.reddit.com/r/EarthPorn/top/?sort=top&t=day I want to do an image of the day kind of situation in html using the top images of the day. I have tried HTML parsing using the DOM library and I've been having some troubles since I'm new to that. I'm trying to figure out the best way to achieve this, and maybe some simple examples. Thank you in advance! This is really a fun learning curve for me.
Upvotes: 0
Views: 42
Reputation: 2613
I previously did something similar as described here:
http://www.nightbluefruit.com/blog/2013/01/how-to-strip-multiple-sections-from-a-string-in-php/
The function included in the post allows you to specify the boundaries of the string you need and then strip it out.
function strip_tag_content($string, $start, $end) {
while (true) {
$ini = strpos($string,$start);
if ($ini === false) return $string;
$len = strpos($string,$end,$ini) + strlen($end) – $ini;
$sub = substr($string,$ini,$len);
$string = str_replace($sub,”\n\n”,$string);
}
return $string;
}
eg
$s = 'Enter the Anchar tag string here';
$s = strip_tag_content($s,'href="','"');
Upvotes: 1