function csdn () {//$uid the classification of the collected articles
$url = "Http://www.csdn.net";
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_connecttimeout, 5);
curl_setopt ($ch, curlopt_encoding, ' UTF8 ');
$content = curl_exec ($ch);
Preg_match_all ("/http\:\/\/\w*\.csdn\.net\/a\/\d*\/\d*\.html/", $content, $match);
$weburl = $match [0];
$weburl =array_unique ($weburl);
$j = 0;
foreach ($weburl as $i = = $vo) {
curl_setopt ($ch, Curlopt_url, $VO);
$content = curl_exec ($ch);
Preg_match_all ("/\ (. *) \<\/h1\>|\/", $content, $match);
if (!emptyempty ($match [2][1])) {
$list [$j] [content ']= $match [2][1];
$list [$j] [' title ']= $match [1][0];
$j + +;
}
}
Print_r ($list);
}
?>
It's easy to see
$list is a collection of news, in the form of a two-dimensional array
If you want to save him to your database, I will not explain ...
It is important to judge whether you are repeating the article in your database
You can encrypt the title by MD5 and then compare it with your database's article title MD5, if true. That means you have the same article in your database.
Note here that you want everyone to copy do not copy manually, please view the source code method copy .....
Because the code on the surface looks like the actual code.
If you are thinkphp. Www.2cto.com. It's the same as mine ... The following is a more convenient code to add a database directly, including repeating data judgment:
function Csdn ($uid) {//$uid classification of collected articles
$url = "Http://www.csdn.net";
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_connecttimeout, 5);
curl_setopt ($ch, curlopt_encoding, ' UTF8 ');
$content = curl_exec ($ch);
Preg_match_all ("/http\:\/\/\w*\.csdn\.net\/a\/\d*\/\d*\.html/", $content, $match);
$weburl = $match [0];
$weburl =array_unique ($weburl);
$j = 0;
foreach ($weburl as $i = = $vo) {
curl_setopt ($ch, Curlopt_url, $VO);
$content = curl_exec ($ch);
Preg_match_all ("/\ (. *) \<\/h1\>|\/", $content, $match);
if (!emptyempty ($match [2][1])) {
$list [$j] [content ']= $match [2][1];
$list [$j] [' title ']= $match [1][0];
$j + +;
}
}
$db =m (' News ');
$news = $db->where ("uid=". $uid)->select ();
$flag =true;
foreach ($list as $i = = $vo) {
foreach ($news as $j = = $value) {
if (MD5 ($value [' title ']) ==md5 ($vo [' title ']) {
$flag =false;
Break
}
}
if ($flag) {
$vo [' uid ']= $uid;
$vo [' Date ']=date (' y-j-m h:i:s ');
$vo [' Author ']=session::get ("admin");
$vo [' Iscommand ']=1;
$rs = $db->add ($VO);
}
$flag =true;
}
}
?>
Excerpt from zouhao619 's column
http://www.bkjia.com/PHPjc/478488.html www.bkjia.com true http://www.bkjia.com/PHPjc/478488.html techarticle php function Csdn () {///$uid collection of articles $url =http://www.csdn.net; $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url) ; curl_setopt ($ch, Curlopt_returntransfer, 1); Cur ...