利用PHP產生二維碼_PHP教程

來源:互聯網
上載者:User

導讀:在二維碼廣泛應用化的今天,在web網站中自動產生對應的二維碼是最基礎的需求。文章介紹了使用PHP自動產生二維碼的三種方式。




get方法實現方式一:

$urlToEncode="163.com";

generateQRfromGoogle($urlToEncode);

function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0') {

$url = urlencode($url);

return ' 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 ""; 注意,不寫header的寫法

return $result;

}

header("Content-type:image/png");

echo qrcode($width,$height,$string);

2.利用php類庫PHP QR Code來實現

首先下載類庫包

地址:http://phpqrcode.sourceforge.net/

下載:http://sourceforge.net/projects/phpqrcode/

  • API文檔

  • 詳細的例子

include "./phpqrcode/phpqrcode.php";

$value="http://www.weste.net";

$errorCorrectionLevel = "L";

$matrixPointSize = "4";

QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);

exit;

?>

http://www.bkjia.com/PHPjc/735051.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/735051.htmlTechArticle導讀:在二維碼廣泛應用化的今天,在web網站中自動產生對應的二維碼是最基礎的需求。文章介紹了使用PHP自動產生二維碼的三種方式。...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.