How to generate QR code in PHP
In this post we will generate QR code (Quick Response Code) using php. QR code is used to read data with smart devices for easy.Hear pass you uel and it will generate qr code of you url.
<?php
// include QR Generator class
include "QRGenerator.php";
// check for post method call.
if($_SERVER["REQUEST_METHOD"] === "POST")
{
$set_url = $_POST['set_url'];
$set_size = $_POST['set_size'];
$example_1 = new QRGenerator($set_url,$set_size);
$qr_img_1 = "<img src=".$example_1->generate().">";
$html_content ='<form method="post" action="">
<table>
<tr>
<td colspan="2">'.$qr_img_1.'</td>
</tr>
<tr>
<td>Text/URL</td>
<td><input type="text" name="url" /></td>
</tr>
<tr>
<td>Size</td>
<td><input type="text" name="size" /> <i>min: 100 and max: 800</i></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="generate" value="Generate" /></td>
</tr>
</table>
</form>';
}
else
{
$html_content ='<form method="post" action="">
<table>
<tr>
<td>Text/URL</td>
<td><input type="text" name="set_url" /></td>
</tr>
<tr>
<td>Size</td>
<td><input type="text" name="set_size" /></td>
</tr>
<tr>
<td rowspan="2"><i>min: 80 and max: 800</i></td>
</tr>
<tr>
<td>
<input type="submit" name="generate" value="Generate" />
</td>
<td>
<input type="reset" name="reset" value="reset" />
</td>
</tr>
</table></form>';
$example_1 = new QRGenerator('http://onlinecode.org',100);
$qr_img_1 = "<img src=".$example_1->generate().">";
$example_2 = new QRGenerator('https://in.yahoo.com/',100);
$qr_img_2 = "<img src=".$example_2->generate().">";
$example_3 = new QRGenerator('https://www.google.com/',100,'ISO-8859-1');
$qr_img_3 = "<img src=".$example_3->generate().">";
$example_4 = new QRGenerator('https://www.bing.com',100,'ISO-8859-1');
$qr_img_4 = "<img src=".$example_4->generate().">";
$html_content .='
<table>
<tr>
<td>'.$qr_img_1.'</td>
<td>'.$qr_img_2.'</td>
</tr>
<tr>
<td>'.$qr_img_3.'</td>
<td>'.$qr_img_4.'</td>
</tr>
</table>';
}
$pre = 1;
$page_title = "How to generate QR code in PHP | onlinecode";
$page_heading = "How to generate QR code in PHP example - onlinecode";
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>
<?php
// add page title
echo $page_title;
?>
</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
img {border-width: 0}
* {font-family:'Lucida Grande', sans-serif;}
</style>
</head>
<body>
<div>
<h2>
<?php
// add page heading
echo $page_heading;
?>
</h2>
<p>
<!-- add this tag after last badge tag -->
<script type="text/javascript">
(function() {
var qr_var = document.createElement('script');
// assign javascript
qr_var.type = 'text/javascript';
// assign async
qr_var.async = true;
// assign javascript
qr_var.src = 'https://apis.google.com/js/plusone.js';
// get script
var get_script = document.getElementsByTagName('script')[0];
get_script.parentNode.insertBefore(qr_var, get_script);
})();
</script>
</div>
<hr />
<p>
<?php
if(!isset($pre)) {
?>
<pre>
<?php
print_r($html_content);
?>
</pre>
<?php } else { ?>
<pre>
<?php
print_r($html_content);
?>
</pre>
<?php } ?>
</p>
</body>
</html>
No comments:
Post a Comment