<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>使用goggle chart api 生成二维码</title>
</head>
<body>
<?php
/**
* 功能:使用goggle chart api 生成二维码
*
* $chl 二维码的数据
* $sideLength 二维码的尺寸
* $EC_level 二维码容错能力
* L - [Default] Allows recovery of up to 7% data loss
* M - Allows recovery of up to 15% data loss
* Q - Allows recovery of up to 25% data loss
* H - Allows recovery of up to 30% data loss
* $margin 二维码白色边距大小
* $choe 二维码数据的编码格式,要求为utf-8
* $cht 使用google api 生成的图片类型,qr表示是qr类型的二维码图
*/
function generateQRCode($chl, $sideLength = 70, $EC_level = 'L', $margin = '0'){
$chl = urlencode($chl);
$result = 'http://chart.apis.google.com/chart?chs='
.$sideLength.'x'.$sideLength.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'&&choe=UTF-8';
return $result;
}
$str = 'Hello,Word!';
$src = generateQRCode($str, 150);
?>
<img src="<?php echo $src; ?>" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>使用goggle chart api 生成二维码</title>
</head>
<body>
<?php
/**
* 功能:使用goggle chart api 生成二维码
*
* $chl 二维码的数据
* $sideLength 二维码的尺寸
* $EC_level 二维码容错能力
* L - [Default] Allows recovery of up to 7% data loss
* M - Allows recovery of up to 15% data loss
* Q - Allows recovery of up to 25% data loss
* H - Allows recovery of up to 30% data loss
* $margin 二维码白色边距大小
* $choe 二维码数据的编码格式,要求为utf-8
* $cht 使用google api 生成的图片类型,qr表示是qr类型的二维码图
*/
function generateQRCode($chl, $sideLength = 70, $EC_level = 'L', $margin = '0'){
$chl = urlencode($chl);
$result = 'http://chart.apis.google.com/chart?chs='
.$sideLength.'x'.$sideLength.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'&&choe=UTF-8';
return $result;
}
//采用MECARD构建的点子名片数据
$mecard = 'MECARD:';
$mecard .= 'N:张强;';
$mecard .= 'NICKNAME:Koma;';
$mecard .= 'TEL:1837304****;';
$mecard .= 'EMAIL:501729495@qq.com;';
$mecard .= 'ADR:湖南理工学院;';
$mecard .= 'URL:http://www.beyond.com/;';
$mecard .= 'NOTE:追寻Beyond精神勇闯新世界!;';
$src = generateQRCode($mecard, 150);
?>
<img src="<?php echo $src; ?>" />
</body>
</html>
扫码二维码 获取免费视频学习资料

- 本文固定链接: http://phpxs.com/post/2919/
- 转载请注明:转载必须在正文中标注并保留原文链接
- 扫码: 扫上方二维码获取免费视频资料
查 看2022高级编程视频教程免费获取