zoukankan      html  css  js  c++  java
  • 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 }
    你所浪费的今天是那些死去的人所奢望的明天,你所厌恶的现在是未来的你所回不去的曾经。
  • 相关阅读:
    共享内存基本操作
    mmap 操作
    busybox 安装问题解决
    ubuntu apt-get failed
    live555 学习资料
    循环队列实现
    socket 聊天室实现
    socket 映射服务器--(可处理多客户端连接(fork),显示退出信息)
    socket 映射服务器程序
    vector和list插入性能对比
  • 原文地址:https://www.cnblogs.com/stj123/p/10712306.html
Copyright © 2011-2022 走看看