Home > Backend Development > PHP Tutorial > php generates QR code business card

php generates QR code business card

WBOY
Release: 2016-07-23 08:54:58
Original
1157 people have browsed it
[PHP] code
  1. /*
  2. * php generate QR code business card
  3. * api Google
  4. * google api QR code generation [QRcode can store up to 4296 alphanumeric types of arbitrary text, specific You can view the QR code data format】
  5. * @param string $chl The information contained in the QR code can be numbers, characters, binary information, or Chinese characters. Data types cannot be mixed, and the data must be UTF-8 URL-encoded. If the information that needs to be transmitted exceeds 2K bytes, please use the POST method
  6. * @param int $widhtHeight The size setting of the generated QR code
  7. * @param string $ EC_level optional error correction level, QR code supports four levels of error correction, used to recover lost, misread, ambiguous, and data.
  8. * L-Default: Can identify 7% of data that has been lost
  9. * M-Can identify 15% of data that has been lost
  10. * Q-Can identify 25% of data that has been lost
  11. * H-Can identify 30% of data that has been lost Data
  12. * @param int $margin The distance between the generated QR code and the picture border
  13. * The format of the QR code business card---vcard
  14. * The format reference is as follows:
  15. BEGIN: VCARD
  16. VERSION: 3.0
  17. FN: Username
  18. TEL;CELL;VOICE:15201280000
  19. TEL;WORK;VOICE:010-62100000
  20. TEL;WORK;FAX:010-62100001
  21. EMAIL;PREF;INTERNET:lzw#lzw.me
  22. URL: http://lzw.me
  23. orG: Zhiwen Studio
  24. ROLE: Product Department
  25. TITLE: CTO
  26. ADR; WORK; POSTAL: No. 35, North Fourth Ring Middle Road, Chaoyang District, Beijing; 100101
  27. REV: 2012-12-27T08:30:02Z
  28. END: VCARD
  29. If you want to customize the required format in more detail, you need to understand the vcard format standard in detail.
  30. */
  31. $vcard = array(
  32. 'vname' => 'username',
  33. 'vtel' => '13700000000',
  34. 'vemail' => 'playby@163.com',
  35. 'vaddress ' => 'Chaoyang District, Beijing',
  36. );
  37. generateQRfromGoogle($vcard);
  38. function generateQRfromGoogle($vcard,$widhtHeight ='150',$EC_level='L',$margin='0')
  39. {
  40. if($vcard){
  41. $chl = "BEGIN:VCARDnVERSION:3.0". //vcard header information
  42. "nFN:'".$vcard['vname'].
  43. "nTEL:".$vcard[ 'vtel'].
  44. "nEMAIL:".$vcard['vemail'].
  45. "nADR:".$vcard['vaddress'].
  46. "nEND:VCARD"; //vcard tail information
  47. echo '< img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.' &chl='.urlencode($chl).'" alt="QR code" widhtHeight="'.$size.'" widhtHeight="'.$size.'"/>';
  48. }
  49. }
  50. ?> ;
Copy code
php


Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template