php实现字符串随机位置插入随机字符串

php实现字符串随机位置插入随机字符串

<?php
header("Content-Type:text/html;charset=utf-8");
$ad=["↑","↓","←","→","↖","↗","↘","↙","↔","↕","➻","➼","➽","➸","➳","➺","➻","➴","➵","➶","➷","➹","▶","►","▷","◁"];
$times = 3; //关键字出现频率
$str = "阿克苏绝对法拉克世界疯了阿拉山口地方就看到las决哦iasfls.sdmflaskdf洛杉矶的法律卡死噢iuoi020990拉开时间的发生了疯狂";
$strlen = mb_strlen($str, "utf-8");
//随机生成插入位置,根据$times决定插入频率
for ( $i = 0; $i < $times; $i ++ ) {
    $arr[] = mt_rand(0, $strlen);
}
$arr = array_unique($arr); //过滤数组重复元素
sort($arr); //对数组重新排序,按照值由小到大
//开始替换
$i = 0;
$str_new = "";
foreach( $arr as $v ) {
    $keyword = $ad[rand(0,count($ad))];
    $str_new .= mb_substr($str, $i, $v - $i, "utf-8") . $keyword;
    $i = $v;
}
$str_new .= mb_substr($str, $i, $strlen - $i, "utf-8");
echo($str_new);

?>


上一篇: centOS 7 设置DNS方法
下一篇: SoftEther 突破防火墙的V***P***N

目前还没有人评论,您发表点看法?
发表评论

评论内容 (必填):