LoginSignup
10
10

More than 5 years have passed since last update.

GoogleChartAPIのQRコード生成のURLを発行するphpスクリプトを組んでみた

Posted at
  • GoogleChartAPIを使うと簡単にQRコードが発行できて便利なんだけど都度URLエンコードなどがめんどくさいのでphpで画面を作ってみた

<!DOCTYPE HTML>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>QR code generator</title>
  </head>

  <body>
    <div>
      <form method="get">
        <table border="0">
          <tr>
            <td align="right"><b>Size</b></td>
            <?php $val = empty($_REQUEST["qr_size"]) ? "300" : $_REQUEST["qr_size"] ?>
            <td><input type="text" name="qr_size" size="3" maxlength="3" value="<?php echo $val ?>"></td>
          </tr>
          <tr>
            <td align="right"><b>URL</b></td>
            <?php $val = empty($_REQUEST["qr_url"]) ? "http://" : $_REQUEST["qr_url"] ?>
            <td><input type="text" name="qr_url" size="128" value="<?php echo $val ?>"></td>
          </tr>
          <tr>
            <td></td>
            <td>
              <input type="reset">
              <input type="submit">
            </td>
          </tr>
        </table>
      </form>
    </div>

    <hr width="50%" align="left">

    <?php if (!empty($_REQUEST["qr_size"])): ?>
      <div>
        <?php
          $url = urlencode($_REQUEST["qr_url"]);
          $qr_code_url = "https://chart.googleapis.com/chart?cht=qr&chs={$_REQUEST["qr_size"]}&chi={$url}";
        ?>
        <div><a href="<?php echo $qr_code_url ?>"><?php echo $qr_code_url ?></a></div>
        <div><img src="<?php echo $qr_code_url ?>"></div>
      </div>
    <?php endif ?>
  </body>
</html>
  • こんな画面になります
    • スクリーンショット 2014-04-22 13.01.33.png
10
10
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10