我有一个带有 url 的页面,其中的描述一个接一个地列出(类似于书签/网站列表)。我如何使用 php 从该页面获取所有 url 并将它们写入 txt 文件(每行一个,只有没有描述的 url)?
页面看起来像这样:
Some description
Other description
Another one
我希望脚本的 txt 输出看起来像这样:
http://link.com
http://link2.com
http://link3.com
最佳答案
单向
$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("/.*<a\s+href=\"/sm","",$u);
$u = preg_replace("/\".*/","",$u);
print $u."\n";
}
}
https://stackoverflow.com/questions/1128774/