// 将原字符串从指定位置断开,分为两个字符串,再将两个字符串和要插入的字符串拼接起来
// str_insert(原字符串,插入的字符串,位置)
function str_insert($string, $replace, $afternum) { // 将指定字符串插入指定的位置后面
$before = substr ( $string, 0, $afternum );
$after = substr ( $string, $afternum );
$newstr = $before . $replace . $after;
return $newstr;
}
/* 测试 */
$str='abcdefg';
$str=str_insert($str, '7', 0);
var_dump($str);
在字符串指定位置插入字符串
最新推荐文章于 2024-03-26 11:51:07 发布