具体如下:
现在网上能搜到很多关于使用PHP生成二维码的例子,主要是两种方法:
第一种:google开放api,如下:
$urlToEncode="http://blog.it985.com";
generateQRfromGoogle($urlToEncode);
function generateQRfromGoogle($chl, $widhtHeight = '150', $EC_level = 'L', $margin = '0')
{
$url = urlencode($url);
echo '
';
}附:API接口地址 https://developers.google.com/chart/infographics/docs/qr_codes
第二种:使用PHP类库 PHP QR CODE
官方地址:http://phpqrcode.sourceforge.net/
下载地址:http://sourceforge.net/projects/phpqrcode/
也可点击此处本站下载。
使用方法:
附官方示例代码地址:http://phpqrcode.sourceforge.net/examples/index.php
当然,还有其他方法生成二维码,这里就不一一介绍了。
下面我们说一下在Symfony下使用EndroidQrCodeBundle生成二维码:
1、使用composer安装
composer require endroid/qrcode-bundle
2、在kernel中注册
3、定义访问路由
EndroidQrCodeBundle: resource: "@EndroidQrCodeBundle/Controller/" type: annotation prefix: /qrcode4、配置 config.xml
endroid_qr_code: size: 100 padding: 10 extension: gif error_correction_level: high foreground_color: { r: 0, g: 0, b: 0, a: 0 } background_color: { r: 255, g: 255, b: 255, a: 0 } #label: "My label" #labelFontSize: 165、在twig中使用
普通文本生成方式:
![]()
![]()
链接生成方式:
上一篇:Symfony2的安装教程
下一篇:twig模板常用语句的示例分析