QRコードメーカーを自作
Web APIを使う=webアプリを作る
入門として、QRコード生成アプリの書き方。
用意するもの
- phpファイル
- htmlファイル
《qrcode.php》
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>QRコード作成サイト</title> <style> body { text-align: center; } </style> </head> <body> <p>生成されたQRコード</p> <?php $keyword = $_GET["keyword"]; $keywordurl = urlencode($keyword); $url="http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=$keywordurl"; ?> <img src="<?php echo $url; ?>"> </body> </html>
《qrcode.html》
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>検索フォーム</title> <style> body { text-align: center; } </style> </head> <body> <p>QRコードにしたい文字を入力してください。</p> <form action="qrcode.php" method="get"> キーワード:<input type="text" name="keyword" size="40"> <input type="submit" value="検索"> </form> </body> </html>