Skip to content

Instantly share code, notes, and snippets.

@bondarewicz
Last active December 14, 2015 20:19
Show Gist options
  • Save bondarewicz/5143150 to your computer and use it in GitHub Desktop.
Save bondarewicz/5143150 to your computer and use it in GitHub Desktop.
PHP: Generate random upper/lower case
<?php
$s = 'mynotsoverylongstring';
print randomcase($s);
function randomcase($string='') {
$length = strlen($string);
$chars = $string;
$str = "";
for ($i = 0; $i < $length; $i++) {
$r = rand(0, 1);
if($r === 0) {
$str.= strtoupper($chars[$i]);
} else {
$str.= strtolower($chars[$i]);
}
}
return $rand_case_str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment