how can we generate coupon code in php dynamically.

Recommended Answers

Hi,

you can generate coupon code by implementing str_shuffle PHP function.

example codes

function get_coupon_code($string_length = 5){

  $coupon_code =  substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz), 0, $string_length);

  }

  echo get_coupon_code(5);

If you want the …

Jump to Post

All 3 Replies

Hi,

you can generate coupon code by implementing str_shuffle PHP function.

example codes

function get_coupon_code($string_length = 5){

  $coupon_code =  substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz), 0, $string_length);

  }

  echo get_coupon_code(5);

If you want the coupon to be an image, you can use imagestring function.

If you try search you will get best ans

Here what i found something for you!

$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$code = "";
for ($i = 0; $i < 10; $i++) {
    $code .= $chars[mt_rand(0, strlen($chars)-1)];
}

You can make your own with some prefix or suffix and use random function

thanks Veedeo and rajeev Kumar.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.