PHP动态插入字符程序
function truncation($allWord=”",$keyWord=”")
{
//删除原有得字符,可以不用
$allWord = str_replace( $keyWord ,”, $allWord );
//字符得总长度
$allLength = strlen($keyWord);
//临时得字符
$tempWord = “”;
//从什么位置开始
$toLength = 90;
//到什么位置
$fromLength = 0;
//有多少循环
$allCyc = (int) ($allLength/$toLength);
//开始执行
for ($i=0;$i<$allCyc;$i++)
{
$fromLength = $i*$fromLength;
$toLength = ($i+1)*$toLength
$tempWord .= substr($allWord,$fromLength,$toLength).$keyWord;
}
//得到剩余得字符
$tempWord .= substr($allWord,$toLength,$allLength);
//返回
return $tempWord;
}
使用方法:truncation($allWord,$keyWord) ;
