码迷,mamicode.com
首页 > 其他好文 > 详细

PDO设置字符集

时间:2019-04-15 20:29:39      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:UNC   als   成功   href   slice   use   ice   dbn   style   

 1 <?php
 2 header("content-type:text/html;charset=GBK");
 3 class CurlClass
 4 {
 5     protected $_pdo;
 6     public function __construct()
 7     {
 8         $this->_pdo =new PDO("mysql:host=127.0.0.1;dbname=student","root","root");
 9         $this->_pdo->query("set names gbk");
10     }
11     //curl
12     public function get($url)
13     {
14         $ch = curl_init();
15         curl_setopt($ch, CURLOPT_URL, "$url");
16         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
17         curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
18         curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,10);
19         curl_setopt($ch, CURLOPT_HEADER, 0);
20         $output = curl_exec($ch);
21         curl_close($ch);
22         return $output;
23     }
24     //规则
25     public function name($url)
26     {
27         $data = $this->get($url);
28         $zheng_ze=‘#<li>\s*<a href="(.*?)".*?>(.*?)<.*\s*<span>.*?</span>\s*</li>#‘;
29         preg_match_all($zheng_ze,$data,$arr);
30         $arr=array_slice($arr,1);
31         foreach($arr[0] as $k=>$v)
32         {
33             $ww=[
34                 ‘title‘=>$arr[1][$k],
35                 ‘content‘=>$arr[0][$k]
36             ];
37             $sql=$this->_pdo->exec("insert into user VALUES (null,‘{$ww[‘title‘]}‘,‘{$ww[‘content‘]}‘)");
38         }
39         if($sql)
40         {
41             echo "添加成功";
42         }
43 
44     }
45 
46 }

 

PDO设置字符集

标签:UNC   als   成功   href   slice   use   ice   dbn   style   

原文地址:https://www.cnblogs.com/stj123/p/10712306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!