file_get_contents()
服务器必须开启:allow_url_fopen = On
- <?php
- if(!ini_get('display_errors')){
- ini_set('display_errors','On');
- }
- error_reporting(E_ALL & ~E_NOTICE);
- $con008=file_get_contents("http://www.baidu.com/");
- $preg008='#<dt><a href="(.*)" title="(.*)">(.*)</a></dt>#iUs';
- preg_match_all($preg008,$con008,$arr008);
- $conn002=mysql_connect("localhost:6305","xxxx","xxxx") or die ("连接数据库服务器失败");
- mysql_select_db("xxxx",$conn002);
- mysql_query("set names 'UTF-8'");
- foreach($arr008[2] as $id=>$v){
- echo '<pre />';
- print_r($v);
- echo '<pre />';
- $sql10="INSERT INTO `caiji_bkhot` (`id`, `title`, `url`) VALUES (NULL , '".iconv("UTF-8", "GBK", $v)."' , '".iconv("UTF-8", "GBK", $arr008[1][$id])."')";
- mysql_query($sql10);
- }
- $last_id008= mysql_insert_id();
- $sql11="delete from `caiji_bkhot` where id <= $last_id008 - 6";
- mysql_query($sql11);
- ?>
本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/963386,如需转载请自行联系原作者