PHP Regular Expression to extract Urls
Posted on: January 13th, 2010
Tags: preg_match_all, preg_replace, Regex, RegularExpressions
The following function extract all links from a page and returns them as an array.
echo var_dump(getLinks( $content ));
function getLinks($content) {
preg_match_all('/(href|src)\=(\"|\')[^\"\'\>]+/i',$content,$media);
$array=preg_replace('/(href|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]);
return $array;
}
Posted in Php | Trackback Url








One Response to “PHP Regular Expression to extract Urls”
1
WP Themes
February 1st, 2010
Permalink this comment
Genial post and this fill someone in on helped me alot in my college assignement. Say thank you you on your information.
0 Trackbacks/Pingbacks
Leave a reply