Skip to content

Instantly share code, notes, and snippets.

@ebi3102
Last active March 8, 2021 02:52
Show Gist options
  • Save ebi3102/33aefb12f1cfd90702f9544006467c44 to your computer and use it in GitHub Desktop.
Save ebi3102/33aefb12f1cfd90702f9544006467c44 to your computer and use it in GitHub Desktop.
<?php
/**
*
*Title: Randome code generator
*Description: randomCodeGenerte($str , $count) generate random code frome $str that is a string. the length of code is equal the value of $count
* $str: a string that can be contain of numbers and charachters. the code create from it's charachters.
* $count: it is a integer that it's defult value is 1. it determineس the length of code would be generate.
*
**/
function randomCodeGenerate($str , $count = 1){
$n = strlen($str);
$out = '';
for($k=0 ; $k < $count ; $k++){
$i = rand(0 , $n - 1);
$out .= substr($str, $i , 1);
}
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment