Symfony生成二維碼的方法_php實(shí)例
Jun 07, 2016 pm 05:09 PM本文實(shí)例講述了Symfony生成二維碼的方法。分享給大家供大家參考,具體如下:
現(xiàn)在網(wǎng)上能搜到很多關(guān)于使用PHP生成二維碼的例子,主要是兩種方法:
第一種:google開放api,如下:
$urlToEncode="http://blog.it985.com"; generateQRfromGoogle($urlToEncode); function generateQRfromGoogle($chl, $widhtHeight = '150', $EC_level = 'L', $margin = '0') { $url = urlencode($url); echo '<img src="/static/imghw/default1.png" data-src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" class="lazy".$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="QR code" />'; }
附:API接口地址 https://developers.google.com/chart/infographics/docs/qr_codes
第二種:使用PHP類庫 PHP QR CODE
官方地址:http://phpqrcode.sourceforge.net/
下載地址:http://sourceforge.net/projects/phpqrcode/
也可點(diǎn)擊此處本站下載。
使用方法:
<?php // include這兩個(gè)文件之一: /* qrlib.php for full version (also you have to provide all library files form package plus cache dir) OR phpqrcode.php for merged version (only one file, but slower and less accurate code because disabled cache and quicker masking configured) */ // 兩句話解釋: // 包含qrlib.php的話需要同其它文件放到一起:文件、文件夾。 // phpqrcode.php是合并后版本,只需要包含這個(gè)文件,但生成的圖片速度慢而且不太準(zhǔn)確 include('./phpqrcode/phpqrcode.php'); // 以下給出兩種用法: // 創(chuàng)建一個(gè)二維碼文件 QRcode::png('code data text', 'filename.png'); // creates file // 生成圖片到瀏覽器 QRcode::png('some othertext 1234'); ?>
附官方示例代碼地址:http://phpqrcode.sourceforge.net/examples/index.php
當(dāng)然,還有其他方法生成二維碼,這里就不一一介紹了。
下面我們說一下在Symfony下使用EndroidQrCodeBundle生成二維碼:
1、使用composer安裝
2、在kernel中注冊(cè)
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Endroid\Bundle\QrCodeBundle\EndroidQrCodeBundle(), ); }
3、定義訪問路由
EndroidQrCodeBundle: resource: "@EndroidQrCodeBundle/Controller/" type: annotation prefix: /qrcode
4、配置 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: 16
5、在twig中使用
普通文本生成方式:
<img src="{{ qrcode_url(message) }}" / alt="Symfony生成二維碼的方法_php實(shí)例" > <img src="{{ qrcode_url(message, extension='png') }}" / alt="Symfony生成二維碼的方法_php實(shí)例" > <img src="{{ qrcode_url(message, size=150) }}" / alt="Symfony生成二維碼的方法_php實(shí)例" >
鏈接生成方式:
本文永久地址:http://blog.it985.com/12340.html
本文出自 IT985博客 ,轉(zhuǎn)載時(shí)請(qǐng)注明出處及相應(yīng)鏈接。
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《php優(yōu)秀開發(fā)框架總結(jié)》、《ThinkPHP入門教程》及《codeigniter入門教程》
希望本文所述對(duì)大家基于Symfony框架的PHP程序設(shè)計(jì)有所幫助。

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The MVC architecture (Model-View-Controller) is one of the most popular patterns in PHP development because it provides a clear structure for organizing code and simplifying the development of WEB applications. While basic MVC principles are sufficient for most web applications, it has some limitations for applications that need to handle complex data or implement advanced functionality. Separating the model layer Separating the model layer is a common technique in advanced MVC architecture. It involves breaking down a model class into smaller subclasses, each focusing on a specific functionality. For example, for an e-commerce application, you might break down the main model class into an order model, a product model, and a customer model. This separation helps improve code maintainability and reusability. Use dependency injection

How to generate and scan QR codes in uniapp requires specific code examples. With the rapid development of the mobile Internet, QR codes have become a very common way of transmitting information. In the cross-platform development framework of uniapp, we can easily implement the generation and scanning functions of QR codes. This article will introduce how to use plug-ins to generate and scan QR codes in uniapp, and give specific code examples. 1. Introduce the plug-in uniapp and develop it based on vue, so we can use vue-q

With the rapid development of information technology, enterprise management systems are becoming more and more popular. Among them, customer relationship management system (CRM) is a very popular enterprise management system. One of the biggest challenges facing businesses today is how to effectively manage customer relationships. Developing an efficient CRM system has become the core task of developing an enterprise. This article will introduce how to use the PHP framework Symfony, combined with its rich functions and documentation, to develop an efficient CRM system. 1. Understand the Symfony framework Symfony is a

The Symfony framework is a popular PHP framework with many advantages. This article will discuss the advantages of the Symfony framework. High degree of flexibility Symfony framework is very flexible and can meet a variety of needs. By using its different components, you can build your own blocks using your own code without having to use a mandatory architecture. This makes the Symfony framework ideal for developing highly complex applications. Strong Security Symfony framework is a very secure

Symfony is a web development framework based on PHP language. It provides a series of tools and components to help developers quickly develop high-quality web applications. The Symfony framework is widely used in web applications, allowing developers to build applications that are highly scalable and flexible. In this article, we will introduce you to the Symfony framework and provide some simple guidance on how to build web applications using the Symfony framework. Install Symfon

Deploy Symfony using Docker: Start development quickly Introduction: With the rapid development of cloud computing and containerization technology, Docker has become one of the preferred tools for developers to deploy and manage applications. Symfony, as a popular PHP framework, can also be deployed through Docker, which greatly simplifies the development and deployment process. This article will introduce how to use Docker to deploy Symfony applications and provide specific code examples. Step 1: Install Docke

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on

Steps to implement user rights management using Symfony framework Symfony framework is a powerful PHP development framework, which can be used to quickly develop high-quality Web applications. When developing web applications, user rights management is an important part that cannot be ignored. This article will introduce the steps to implement user rights management using the Symfony framework, with code examples. Step 1: Install the Symfony framework First, we need to install the Symfony framework in the local environment. able to pass
