我有这个函数将一些随机字符放入字符串中:
function random($string) {
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$shuffle_start = substr(str_shuffle($chars), 0, 6);
$shuffle_end = substr(str_shuffle($chars), 0, 6);
$letters = str_split($string);
$str = '';
$count = count($letters);
foreach($letters AS $l) {
$count--;
$str .= $l;
if($count) {
$str .= substr(str_shuffle($chars), 0, 5);
}
}
return $shuffle_start . $str . $shuffle_end;
}
此函数从字符串“hello”:aApi3VhKJrDjeAbCkalprX7ll7N0Qjo3qymiw
打印出来。现在,我想从字符串中删除随机字符,以便清楚地看到单词“hello”。
我该怎么做?
答案 0 :(得分:0)
向后移动。从开始和结束开始删除6个字符,然后获取每个第六个字符
function unrandom($str){
$base = substr($str, 6, strlen($str)-12);
$ret = '';
for($i=0;$i < strlen($base); $i+=6) {
$ret .= substr($base, $i,1);
}
return $ret;
}