I would to see another way to convert some of the character in the string to mixed case i think my way is not the optimal way..
$arr_str = str_split("w2abcd");
$atCase = "";
foreach ($arr_str as $cha) {
$toup = rand(0, 1);
if($toup == 1开发者_JAVA百科){ $atCase .= ucfirst($cha); } else { $atCase .= $cha;}
}
$rtnstr = $atCase;
looks pretty good. the optimization may be like this:
$str = "w2abcd";
for ($i=0,$c=strlen($str);$i<$c;$i++)
$str[$i] = rand(0, 100) > 50?$strtoupper($str[$i]):$str[$i];
return $str;
Well, just my variant:
<?php
$str = str_split(strtolower('some text'));
foreach ($str as &$char)
{
if (rand(0, 1)) $char = strtoupper($char);
}
print implode('', $str);
精彩评论