PDO设置字符集
Posted stj123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PDO设置字符集相关的知识,希望对你有一定的参考价值。
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设置字符集的主要内容,如果未能解决你的问题,请参考以下文章