A summary of the method of generating two-dimensional code by PHP
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.