PHP Collection CSDN Home News _php Tutorials

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.