how can we generate coupon code in php dynamically.

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.