Night | Snow

PHP Regular Expression to extract Urls

Posted on: January 13th, 2010

Tags: , , ,

The following function extract all links from a page and returns them as an array.

$content = file_get_contents("http://www.simra.ch");
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

News

Martin Fischer said:

Client and partner of simra.ch

Wir können Simon Schärer als kompetenter und zuverlässiger Programmierer höchst weiterempfehlen. Er ist nicht nur ein guter Programmierer, sondern auch ein ausgezeichneter Designer.
Danke Developer’s Island

Follow us on Twitter

favorite

I get asked a lot - which SDK should we use for web programming? I recommend Netbeans

my toolbar

Simra GameMP3 playersubscribe to RSSMy delicious bookmarksFacebookTwitterE-mail

One Response to “PHP Regular Expression to extract Urls”

RSS Feed Icon  Subscribe to comments follow-up

WP Themes's Avatar

1

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

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Latest Tweet

loading...