A summary of the method of generating two-dimensional code by PHP

time:14-03-28 forum:PHP tools and code
  http://www.phpernote.com/php-function/638.html

the current trend in the Internet has become the trend of the Internet, in the end of 2012, two-dimensional code quietly popular, gradually infiltrated into all aspects of our lives. When browsing the news, more information can be obtained by scanning the two-dimensional code information provided by the website; more friends can be made by scanning the two-dimensional code of the mobile phone; the food safety information can be obtained by scanning the two-dimensional code when shopping, and even the train and the plane also have a two dimensional code "bus". It is more convenient for the people to travel. The two dimensional code is becoming more and more popular. We need to understand what is two-dimensional code. As a PHP programer, we need to know how to use PHP to generate two-dimensional code. Talk less and say the right thing.

two methods of using PHP to generate two-dimensional code are introduced in this paper.

(1) use Google to generate open interface of two-dimensional code, the code is as follows:
[code]
/**
* Google API two-dimensional code generation [QRcode can store up to 4296 alphanumeric types of arbitrary text, specifically can view two-dimensional code data format]
* @param string two-dimensional code contained letters Interest can be numbers, characters, binary information, and Chinese characters. Data type can not be mixed, data must pass through UTF-8 URL-encoded. if the information needed to pass more than 2K bytes, please use POST
* @param int $widhtHeight to generate the size of a two-dimensional code in the
* @param string $EC_level optional correction level, the code supports four grade error correction, used to restore the lost Misread, blurred, data.
* M- can identify data that has lost 15%
* Q- can identify lost 25% of data
* H- can identify data
* @param that has lost 30%.
*/
function generateQRfromGoogle ($data, $widhtHeight='150', $EC_level='L', $margin='0') {
$url=urlencode. Chld='.$EC_level.'|'.$margin.'.amp; chl='.$data.'.quot; widhtHeight=.quot;'.$widhtHeight.'.quot; widhtHeight=.quot;'.$widhtHeight.'.quot; /.gt; '
}[/code]

usage:
[code]$data='. The generated two-dimensional code pictures are as follows:


post method to make the request Google API to generate a two-dimensional code:
[code]function QRcode ($width, $height, $string) / > $; ';
$post_data.#91;'chs'.#93; =$width..Quot; x.quot;.$height;
$post_data.#91;'chl'.#93; =$string;
$post_data.#91; stationery / >; Ata_Array.#91;.#93; =$key.'='.$value;
}
$data=implode (.Quot;.Amp;.Quot; $data_Array);
$ch=curl_init.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec ($ch);
//echo.Quot;.Lt; img.
  • 2

prev:Guo Degang, airborne in April, Ji'nan pr... next:Ji'nan promotes the appointment of civil...
post comment
Notice



approved   A rare picture of the old Ji'nan! Th...   The deep mountain women's back husba...   Sichuan Leshan 84 year old Lao Tai a...   Loss of breast and cancer coexistenc...   The "ship man" in the city: the aver...
rand   PHP does not use iconv () function U...   Conversion of GB2312 and Unicode cod...   PHP uses iconv () function to solve ...   PHP uses the iconv () function to tr...   PHP encryption and decryption thunde...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com