PHP驱动的二维码发生器

PHP驱动的二维码发生器,php,Php,此二维码生成器仅允许您为一个内容字段生成二维码。我想添加一种方法来生成您可以在此处使用php生成的所有信息: 我希望用户能够编码MECARD和vCard 这就是我到目前为止所做的: <div id="generator"> <form target="qrcode-frame" action="gen.php" method="post"> <fieldset> <legend>Size:</legend&

此二维码生成器仅允许您为一个内容字段生成二维码。我想添加一种方法来生成您可以在此处使用php生成的所有信息:

我希望用户能够编码MECARD和vCard

这就是我到目前为止所做的:

<div id="generator">
    <form target="qrcode-frame" action="gen.php" method="post">
      <fieldset>
        <legend>Size:</legend>
         <input type="radio" name="size" value="150x150" checked>150x150<br>
         <input type="radio" name="size" value="200x200">200x200<br>
         <input type="radio" name="size" value="250x250">250x250<br>
         <input type="radio" name="size" value="300x300">300x300<br>
      </fieldset>
      <fieldset>
        <legend>Encoding:</legend>
        <input type="radio" name="encoding" value="UTF-8" checked>UTF-8<br>
        <input type="radio" name="encoding" value="Shift_JIS">Shift_JIS<br>
        <input type="radio" name="encoding" value="ISO-8859-1">ISO-8859-1<br>
      </fieldset>
      <fieldset>
        <legend>Content:</legend>
        <textarea name="content"></textarea>
      </fieldset>         
      <fieldset>
        <legend>Error correction:</legend>
        <select name="correction">
            <option value="L" selected>L</option>
            <option value="M">M</option>
            <option value="Q">Q</option>
            <option value="H">H</option>
        </select>
      </fieldset>         
      <input type="submit" value="Generate"></input>
    </form>
</div>  
<div id="result">
    <iframe name="qrcode-frame" frameborder="0"  id="qrcode" src="gen.php" height="315px;" width="350px"></iframe>
</div>

尺寸:
150x150
200x200
250x250
300x300
编码: UTF-8
班次_JIS
ISO-8859-1
内容: 错误更正: L M Q H
在另一个文件中:

    <?php
if(isset($_REQUEST['content'])){
    //capture from the form
    $size          = $_REQUEST['size'];
    $content       = $_REQUEST['content'];
    $correction    = strtoupper($_REQUEST['correction']);
    $encoding      = $_REQUEST['encoding'];

    //form google chart api link
    $rootUrl = "https://chart.googleapis.com/chart?cht=qr&chs=$size&chl=$content&choe=$encoding&chld=$correction";

    //print out the image
    echo '<img src="'.$rootUrl.'">';
}
?>

这很有效,但非常有限


谢谢

您可以在这里找到详细信息

还有这里的例子

如果您需要html代码和php代码,请用您需要创建的数据写一条注释


我将为您创建一个示例。

这个示例非常适合我 您必须处理错误(空文本框)

例如:

必须包括jquery.js html:


函数get_url()
{
$.ajax(
{
键入:“POST”,
url:'gen.php',
数据类型:“html”,
数据:{Name:$('#Name').val(),公司:$('#Company').val(),标题:$('#Title').val(),电话号码:$('#电话号码').val(),电子邮件:$('#Email').val(),地址:$('#地址').val(),地址:$('#地址#2').val(),网站:$('#网站').val(),备忘录编码:$('#条形码编码:$,所选条形码尺寸:$):$(“#条形码大小选项:选定”).val(),错误纠正:$(“#错误纠正选项:选定”).val(),字符编码:$(“#字符编码选项:选定”).val(),
成功:功能(msg){
$('#myurl').val(msg);
$('img').attr('src',msg);
} });
}
名称
单位
标题
电话号码
电子邮件
地址
地址2
网站
备忘录
编码
麦卡德
vCard
条码大小
小的
中等
大的
纠错
L
M
Q
H
字符编码
UTF-8
ISO-8859-1
班次
生成→    
嵌入此URL:
php:

<?php
$post = (!empty ($_POST)) ? true : false;
if (!$post) {
    die();
}
$data = '';
@ $Name = $_POST['Name'];
@ $Company = $_POST['Company'];
@ $Title = $_POST['Title'];
@ $Phone_number = $_POST['Phone_number'];
@ $Email = $_POST['Email'];
@ $Address = $_POST['Address'];
@ $Address_2 = $_POST['Address_2'];
@ $Website = $_POST['Website'];
@ $Memo = $_POST['Memo'];
@ $Encoding = $_POST['Encoding'];
@ $Barcode_size = $_POST['Barcode_size'];
@ $Error_correction = $_POST['Error_correction'];
@ $Character_encoding = $_POST['Character_encoding'];
$Barcode_size = $Barcode_size . "x" . $Barcode_size;
$data = 'http://chart.apis.google.com/chart?';  // url
$data .= 'cht=qr&chs=' . $Barcode_size . '&chld=' . $Error_correction . '&choe=' .$Character_encoding . '&chl=' . $Encoding . ':'; // required data
$data .= 'name:' . $Name . ';Company:' . $Company . ';Title:' . $Title . ';Phone_number:' . $Phone_number . ';Email:' . $Email . ';Address:' . $Address . ';Website:' . $Website . ';Memo:' . $Memo . ';;'; // your data   -> name :value ; and at the end of the line -> ;
echo $data;
?>

我们有重要的参数

cht=qr                                  Required -> Specifies a QR code
chs=<width>x<height>                    Required -> Image size
chl=<data>                              Required -> more than 2K bytes (minus the other URL characters), you will have to send your data using POST
choe=<output_encoding>                  Optional -> UTF-8 , Shift_JIS , ISO-8859-1
chld=<error_correction_level>|<margin>  Optional ->

error_correction_level
L - [Default] Allows recovery of up to 7% data loss
M - Allows recovery of up to 15% data loss
Q - Allows recovery of up to 25% data loss
H - Allows recovery of up to 30% data loss

margin - The width of the white border around the data portion of the code. 
2-参数

$data .= 'cht=qr&chs=' . $Barcode_size . '&chld=' . $Error_correction . '&choe=' .$Character_encoding . '&chl=' . $Encoding . ':'; // parameters
3-我们的数据

$data .= 'name:' . $Name . ';Company:' . $Company . ';Title:' . $Title . ';Phone_number:' . $Phone_number . ';Email:' . $Email . ';Address:' . $Address . ';Website:' . $Website . ';Memo:' . $Memo . ';;'; 
结果会是这样

   http://chart.apis.google.com/chart?cht=qr&chs=120x120&chld=L&choe=UTF-8&chl=MECARD:name:MyName;Company:MyCo;Title:ttt;Phone_number:ttt;Email:ttt;Address:ttt;Website:tt;Memo:ttt;;
请注意以下数据:

name MyName->这样写->name:MyName

数据名称:数据值;//只能发送不带名称的值


在这一行的末尾,您会发现两个分号

这行行吗?如果您想使用HTTPS进行此更改“”>>”,其余的都是正常的。
$data .= 'name:' . $Name . ';Company:' . $Company . ';Title:' . $Title . ';Phone_number:' . $Phone_number . ';Email:' . $Email . ';Address:' . $Address . ';Website:' . $Website . ';Memo:' . $Memo . ';;'; 
   http://chart.apis.google.com/chart?cht=qr&chs=120x120&chld=L&choe=UTF-8&chl=MECARD:name:MyName;Company:MyCo;Title:ttt;Phone_number:ttt;Email:ttt;Address:ttt;Website:tt;Memo:ttt;;