<?php
if(!file_exists("1.txt")){
fopen("1.txt","w");
}
$txt = file_get_contents("http://www.baidu.com");//preg_match_all("|<a\s+href=(?<url>.+?)>(?<content>.+?)</a>|",$txt,$match);
var_dump($match);foreach ($match[0] as $val){
echo htmlspecialchars($val)."<br>";
$str .= $val;
}
file_put_contents("1.txt",$str);
?>
对于这段代码,如何使输出的txt文件里只显示URL和链接名?并且实现分行?比如在txt里显示的结果为
http://passport.baidu.com/?login&tpl=mn登录
http://news.baidu.com新 闻
http://tieba.baidu.com贴 吧
http://zhidao.baidu.com"知 道
http://mp3.baidu.comMP3
.
.
.
.
if(!file_exists("1.txt")){
fopen("1.txt","w");
}
$txt = file_get_contents("http://www.baidu.com");//preg_match_all("|<a\s+href=(?<url>.+?)>(?<content>.+?)</a>|",$txt,$match);
var_dump($match);foreach ($match[0] as $val){
echo htmlspecialchars($val)."<br>";
$str .= $val;
}
file_put_contents("1.txt",$str);
?>
对于这段代码,如何使输出的txt文件里只显示URL和链接名?并且实现分行?比如在txt里显示的结果为
http://passport.baidu.com/?login&tpl=mn登录
http://news.baidu.com新 闻
http://tieba.baidu.com贴 吧
http://zhidao.baidu.com"知 道
http://mp3.baidu.comMP3
.
.
.
.
<?php
if(!file_exists("1.txt")){
fopen("1.txt","w");
}
$txt = file_get_contents("http://www.baidu.com");//
preg_match_all("|<a\s+href=(.+?)>(.+?)</a>|",$txt,$match);
var_dump($match);
foreach ($match[1] as $key =>$val){
$match[2][$key] = iconv("GB2312", "UTF-8", $match[2][$key]);
$str .= $match[1][$key].$match[2][$key]."\n";
}
file_put_contents("1.txt",$str);
?>