本文共 1300 字,大约阅读时间需要 4 分钟。
方法一:利用google api的方式
api参数简要说明
//choe为编码,默认为utf-8
//数据大于2K请用post进行发送 /* chld错误处理 L:默认,允许恢复7%的数据丢失 M:允许15% Q:允许25% H:允许30% */实现方法一:get方式
$width = 300;
$height = 300; $data = "this is a test";echo "<img src =\"http://chart.apis.google.com/chart?cht=qr&chs=".$width."x".$height."&chl=".$data."&choe=UTF-8\" >";
实现方法二:模拟post方式
$width = 300;
$height = 300; $string = "姓名:王八 性别:不男不女姓名:王八 性别:不男不女姓名:王八 性别:不男不女姓名:王八 性别不女"; 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);实现方法二
方法二:php类库PHP QR Code
地址:
下载:
php支持请参考: 方法四:QRcode Perl CGI & PHP scripts 地址:
转载地址:http://nfsmb.baihongyu.com/