How to Generate QR code in PHP using tc-lib-barcode
source link: https://www.laravelcode.com/post/how-to-generate-qr-code-in-php-using-tc-lib-barcode
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Generate QR code in PHP using tc-lib-barcode
In this article i will share with you how to generate QR code in php using tc-lib-barcode library with example. as you knonw in some application we want to generate dynamic QR code with some dynamic data in PHP and the tc-lib-barcode
provide you that type of functionality with very easy way.
Download the tc-lib-barcode library from here and implement in your PHP application. here i share a very simple QR code generate script help of this code you can implement dynamic QR code generation functioonality in your PHP application.
HTML CODE
<form method="post" name="frmQRGenerator" id="frm-qr"
onSubmit="return validate();">
<div class="form-row">
Email: <input type="text" name="email_field" id="email_field"
class="input-field" />
</div>
<div>
<input type="submit" name="generate" class="submit-button"
value="Generate QR Code" />
</div>
</form>
<div id="validation-info"></div>
<script src="jquery-3.2.1.min.js"></script>
<script>
function validate() {
var valid = true;
var emailRegexp = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i
$("#validation-info").hide();
$("#validation-info").html();
if ($("#email_field").val() == "") {
$("#validation-info").show();
$("#validation-info").html("Email is required.");
valid = false;
} else if (!(emailRegexp.test($("#email_field").val()))) {
$("#validation-info").show();
$("#validation-info").html("Invalid Email.");
valid = false;
}
return valid;
}
</script>
PHP CODE
<?php
if (! empty($_POST["email_field"])) {
require ('tc-lib-barcode/vendor/autoload.php');
$barcode = new \Com\Tecnick\Barcode\Barcode();
$targetPath = "qr-code/";
if (! is_dir($targetPath)) {
mkdir($targetPath, 0777, true);
}
$bobj = $barcode->getBarcodeObj('QRCODE,H', $_POST["email_field"], - 16, - 16, 'black', array(
- 2,
- 2,
- 2,
- 2
))->setBackgroundColor('#f0f0f0');
$imageData = $bobj->getPngData();
$timestamp = time();
file_put_contents($targetPath . $timestamp . '.png', $imageData);
?>
<div class="result-heading">Output:</div>
<img src="<?php echo $targetPath . $timestamp ; ?>.png" width="150px"
height="150px">
<?php
}
?>
i hope it will be help to you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK