zoukankan      html  css  js  c++  java
  • php生成二维码

    <?php
    $urlToEncode="163.com";  
    generateQRfromGoogle($urlToEncode);  
    function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')  {  
         $url = urlencode($url);  
         return  '<img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&    chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="QR code" widhtHeight="'.$size.'" widhtHeight="'.$size.'"/>';  
    }  

    //post方法实现方式:
    $width = 300;  
    $height = 300;  
    $string = "163.com";  
    function qrcode($width,$height,$string)  
    {  
        $post_data = array();  
        $post_data['cht'] = 'qr';  
        $post_data['chs'] = $width."x".$height;  
        $post_data['chl'] = $string;  
        $post_data['choe'] = "UTF-8";  
        $url = "http://chart.apis.google.com/chart";  
        $data_Array = array();  
        foreach($post_data as $key => $value)  
        {  
            $data_Array[] = $key.'='.$value;  
        }  
        $data = implode("&",$data_Array);  
        //echo $data;  
        $ch = curl_init();  
        curl_setopt($ch, CURLOPT_POST, 1);  
        curl_setopt($ch, CURLOPT_HEADER, 0);  
        curl_setopt($ch, CURLOPT_URL, $url);      
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
        $result = curl_exec($ch);  
       
        //echo "<img src ="data:image/png;base64,".base64_encode($result)."" >"; 注意,不写header的写法  
      
         return $result;  
    }  
      
    header("Content-type:image/png");  
    echo qrcode($width,$height,$string); 

  • 相关阅读:
    Go学习2-切片
    Go学习1-MOD
    lua学习之逻辑运算符not,and,or
    google protobuf c++ 反射
    我要谴责一下,你们复制别人的答案好歹仔细看看
    远程登录redis
    openssl进行RSA加解密(C++)
    linux通过进程名查看其占用端口
    简体字丶冯|服务网关kong-docker安装
    简体字冯|docker-安装docker私有库
  • 原文地址:https://www.cnblogs.com/jiaosq/p/5620243.html
Copyright © 2011-2022 走看看