Posted By

gdvickery on 03/02/09


regex file html links extract

Versions (?)

Who likes this?

4 people have marked this snippet as a favorite


Extract all links from a page using Regex

 / Published in: PHP

These 4 lines of code can be used to extract and return all links from any page using regex patterns. If links are found, an array is returned, else boolean false is returned.

  1. $pageData = file_get_contents('');
  2. if(preg_match_all('/<a\s+href=["\']([^"\']+)["\']/i', $pageData, $links, PREG_PATTERN_ORDER))
  3. return array_unique($links[1]);
  4. return false;

Report this snippet  


RSS Icon Subscribe to comments
Posted By: Unreal on March 11, 2009

This is a bit more efficient

Posted By: on January 15, 2019

download best software to android root use app kingo or 360 for pc mac ios windows 10 8 1 7 xp computer www

You need to login to post a comment.