Last active
March 8, 2021 02:52
-
-
Save ebi3102/33aefb12f1cfd90702f9544006467c44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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