How to get all urls from page (php) – Here in this article, we will share some of the most common and frequently asked about PHP problem in programming with detailed answers and code samples. There’s nothing quite so frustrating as being faced with PHP errors and being unable to figure out what is preventing your website from functioning as it should like and . If you have an existing PHP-based website or application that is experiencing performance issues, let’s get thinking about How to get all urls from page (php).
I have a page with urls with descriptions listed one under another (something like bookmarks/list of sites). How do I use php to get all urls from that page and write them to txt file (one per line, only url without description)?
Page looks like this:
And I would like script’s txt output to look like this:
Solution :
one way
$url="http://wwww.somewhere.com";
$data=file_get_contents($url);
$data = strip_tags($data,"<a>");
$d = preg_split("/</a>/",$data);
foreach ( $d as $k=>$u ){
if( strpos($u, "<a href=") !== FALSE ){
$u = preg_replace("/.*<as+href="/sm"","""",$u)