Voucher Code Generator - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Voucher Code Generator.php

  1. <?php
  2.  
  3. $row = 10; //total row of code
  4. $length = 8; //length of code
  5.  
  6. function code_generator($row, $length)
  7. {
  8.     for($i=0; $i<$row; $i++)
  9.     {
  10.         $part1 = md5( $i.mt_rand() );
  11.         $part1 = preg_replace('/^(.{'.($length-2).'}).*/', '$1', $part1);
  12.         $part2 = preg_replace('/.*(.{2})$/', '$1', uniqid());
  13.         $code = $part1.$part2;
  14.         
  15.         print $code;
  16.         print "\n";
  17.     }
  18. }
  19.  
  20. print "\n";
  21. code_generator($row, $length);
  22.  
File Description
  • Voucher Code Generator
  • PHP Code
  • 30 Aug-2022
  • 452 Bytes
You can Share it: