Table of Contents
Preface
Start
On the right track
Overall idea
Method 1: Composer and endroid/QrCode
Method 2: Use phpqrcode
Home PHP Framework ThinkPHP About the generation method of thinkphp5 QR code in xampp environment

About the generation method of thinkphp5 QR code in xampp environment

Feb 15, 2021 am 10:13 AM
php

Generation of thinkphp5 QR code in xampp environment

Preface

Due to the functional needs of the team, we need to use PHP to make a QR code based on Our action of generating a QR code from the given URL is a tortuous process. I will summarize it here after it is completed.

Start

At the beginning, I went in the wrong direction. My thinking at the time: Since you want to generate a QR code, you need to know how to generate a QR code. mechanism, so I searched for QR codes on the Internet and got the following results:
About the generation method of thinkphp5 QR code in xampp environment

我粗略读了一遍之后顿悟:
显然,这不是我想要的(如果研究这东西,估计未来几周不用干别的了)
Copy after login

On the right track

Although I went in the wrong direction, I still understand it simply Now that we know the QR code, how can we implement the functions we need? This time I decided to be simple and crude

About the generation method of thinkphp5 QR code in xampp environment

Google was honest with me. Someone had already written these functions before me, so I started to get on the right track.

Overall idea

  • The functions we need have been written in PHP on the Internet. Just like we quoted the library in think, we only need to generate QR codes online Download the library and then reference it to generate a QR code quickly and conveniently. With the idea settled, let’s start working.

The author found two methods, and finally used the second one

Method 1: Composer and endroid/QrCode

  • Mentioned php download section For third-party libraries, we must mention composer. This is a powerful library management tool in PHP that can help us download other libraries on the Internet. This magical thing is also introduced in the official documentation (as shown below)

About the generation method of thinkphp5 QR code in xampp environment

  • Currently, the author is using the windows environment. I downloaded it according to the link in the official document and started happily going all the way to next. Then the problem came

About the generation method of thinkphp5 QR code in xampp environment

This is a photo I found online (from the novice tutorial: composer installation). When I installed it, no address appeared, so I was confused. This is What's the meaning?

After thinking about it, the management tool we installed is related to php, and we need to find the php.exe file in the novice tutorial picture, which leads to the following question: Where is php?

  • XAMPP

    Baidu Encyclopedia: XAMPP (Apache MySQL PHP PERL) is a powerful website building integration software package. It can be seen that the xampp we use has PHP integrated in it. Next, start looking for files
    About the generation method of thinkphp5 QR code in xampp environment

找到文件,安装完成,在我们的thinphp5文件夹下,输入指令来安装好第三方库

    $ composer require endroid/qr-code
Copy after login

In this way, our library file After loading, if you want to develop code, you can refer to this blog

http://www.cnbreak.org/biancheng/thinkphp5/wechatwebpage/760.html

Method 2: Use phpqrcode

The author uses this method, and it is relatively simple to use (but it seems that it cannot be used in thinkphp6). We download the third-party library directly from the Internet

Download link https:// sourceforge.net/projects/phpqrcode/files/releases
Official documentation http://phpqrcode.sourceforge.net/docs/html/annotated.html

After downloading
About the generation method of thinkphp5 QR code in xampp environment

Note: It must be in the extends directory
The library we downloaded with composer is in vender, and the third-party library downloaded from outside will only work if it is placed in extends.
The following is the code for the second method

function qrcode($level = 'L', $size = 4){
    // 导入Phpqrcode插件文件require_once EXTEND_PATH.'phpqrcode/phpqrcode.php';
    
    //设置url
    $url1 = 'https://www.baidu.com/s?wd=666&rsv_spt=1&rsv_iqid=0xfea0cab90000241d&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_dl=ib&rsv_sug3=4&rsv_sug1=3&rsv_sug7=100&rsv_sug2=0&rsv_btype=i&inputT=528&rsv_sug4=1203';

    // 容错级别
    $errorCorrectionLevel = $level;
    // 生成图片大小
    $matrixPointSize = intval($size);
    // 生成二维码图片
    $object = new QRcode();
    // 这个一定要加上,清除缓冲区
    ob_end_clean();
    // 第二个参数false的意思是不生成图片文件,如果你写上‘picture.png’则会在根目录下生成一个png格式的图片文件
    $object->png($url1, false, $errorCorrectionLevel, $matrixPointSize, 2);
}
Copy after login

The meaning of the relevant parameters:

About the generation method of thinkphp5 QR code in xampp environment

  • $text is the url parameter
  • $outfile The default is no, no file is generated, only the QR code image is returned, otherwise the saving path needs to be given
  • $level QR code Fault tolerance rate, default L(7%), M(15%), Q(25%), H(30%)
  • $size QR code image size, default 4
  • $ margin The size of the blank area of ​​the QR code
  • $saveabdprint The QR code is saved and displayed. $outfile must pass the path
  • $back_color Background color
  • $fore_color Draw the QR code Color
  • tip: The color must be passed in hexadecimal color value, and replace "#" with "0x"; such as #FFFFFF => 0xFFFFFF

##Summary

When we want to implement a function, generally speaking, someone will have written this thing before us. First, we should study the implementation ideas of this function by ourselves, and then think of ways to find it. Relevant document methods can be used to implement functions.

The above is the detailed content of About the generation method of thinkphp5 QR code in xampp environment. For more information, please follow other related articles on the PHP Chinese website!

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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles