Symfony method for generating two-dimensional code _php example

Source: Internet
Author: User
Tags php class

The method of generating two-dimensional code by Symfony is described in this paper. Share to everyone for your reference, specific as follows:

There are a lot of examples of using PHP to generate two-dimensional code on the Web, mainly in two ways:

The first: Google Open API, as follows:

$urlToEncode = "http://blog.it985.com";
Generateqrfromgoogle ($urlToEncode);
function Generateqrfromgoogle ($chl, $widhtHeight = ' m ', $EC _level = ' L ', $margin = ' 0 ')
{
  $url = UrlEncode ($url) ;
  Echo '  
 

Appendix: API Interface Address Https://developers.google.com/chart/infographics/docs/qr_codes

Second: Using PHP class library PHP QR CODE

Official address: http://phpqrcode.sourceforge.net/

Download Address: http://sourceforge.net/projects/phpqrcode/

Can also click here to download the site.

How to use:

<?php
//include one of these two files:/
* qrlib.php for full
version (also your have to provide all library files
form Package plus cache dir)
OR phpqrcode.php for merged version (only one file,
but slower and less code BEC Ause disabled cache
and quicker masking configured)
* *//
/Two sentence explanation://////
with qrlib.php words need to be put together with other files: files, folders.
//phpqrcode.php is a merged version that only needs to include this file, but the resulting picture is slow and inaccurate including
('./phpqrcode/phpqrcode.php ');
Here are two uses:
//Create a two-dimensional code file
QRCode::p ng (' Code data text ', ' filename.png ');
Creates file
//Generate picture to browser
qrcode::p ng (' some othertext 1234 ');
? >

With official sample code address: http://phpqrcode.sourceforge.net/examples/index.php

Of course, there are other ways to generate two-dimensional code, this is not one of the introduction.

Let's talk about using Endroidqrcodebundle to generate two-dimensional code under Symfony:

1, the use of composer installation

Copy Code code as follows:
Composer require Endroid/qrcode-bundle

2. Register in kernel

<?php
//app/appkernel.php public
function Registerbundles ()
{
  $bundles = array (
    //...
    ) New Endroid\bundle\qrcodebundle\endroidqrcodebundle (),
  );
}

3. Define Access Routing

Endroidqrcodebundle:
  resource:  "@EndroidQrCodeBundle/controller/"
  type:    annotation
  Prefix:   /qrcode

4. Configure 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 Labe L "
  #labelFontSize: 16

5. Use in twig

Normal text generation method:

 


Link delivery form:

Copy Code code as follows:

This article permanent address: http://blog.it985.com/12340.html
This article comes from IT985 blog, reprint, please indicate the source and corresponding link.

More interested in PHP related content readers can view the site topics: "PHP graphics and pictures Operating skills summary", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course" and "CodeIgniter Introductory Course"

I hope this article will help you with the PHP program design based on Symfony framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.