国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial Symfony生成二維碼的方法_php實(shí)例

Symfony生成二維碼的方法_php實(shí)例

Jun 07, 2016 pm 05:09 PM
symfony Generate QR code

本文實(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&#63;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)擊此處本站下載。

使用方法:

<&#63;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');
&#63;>

附官方示例代碼地址:http://phpqrcode.sourceforge.net/examples/index.php

當(dāng)然,還有其他方法生成二維碼,這里就不一一介紹了。

下面我們說一下在Symfony下使用EndroidQrCodeBundle生成二維碼:

1、使用composer安裝

復(fù)制代碼 代碼如下:
composer require endroid/qrcode-bundle

2、在kernel中注冊(cè)

<&#63;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í)例" >

鏈接生成方式:

復(fù)制代碼 代碼如下:
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ì)有所幫助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

An advanced guide to PHP MVC architecture: unlocking advanced features An advanced guide to PHP MVC architecture: unlocking advanced features Mar 03, 2024 am 09:23 AM

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

uniapp implements how to generate QR codes and scan QR codes uniapp implements how to generate QR codes and scan QR codes Oct 19, 2023 am 08:18 AM

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

Develop an efficient CRM system using the PHP framework Symfony Develop an efficient CRM system using the PHP framework Symfony Jun 27, 2023 pm 04:17 PM

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

What are the advantages of Symfony framework? What are the advantages of Symfony framework? Jun 03, 2023 am 09:21 AM

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

PHP Implementation Framework: Symfony Getting Started Tutorial PHP Implementation Framework: Symfony Getting Started Tutorial Jun 18, 2023 pm 01:18 PM

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 with Docker: Get started developing quickly Deploy Symfony with Docker: Get started developing quickly Oct 20, 2023 pm 12:19 PM

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

Symfony vs Yii2: Which framework is better for developing large-scale web applications? Symfony vs Yii2: Which framework is better for developing large-scale web applications? Jun 19, 2023 am 10:57 AM

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 Steps to implement user rights management using Symfony framework Jul 29, 2023 pm 11:33 PM

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

See all articles