PHP在字符串指定位置插入一段字符串

WBOY
Release: 2016-06-20 13:02:48
Original
2025 people have browsed it

php在字符串指定位置插入一段字符串

//插入一段字符串
/*
 * @param string $str    # 待处理字符串
 * @param int    $i      # 插入位置
 * @param string $substr # 需要插入的字符串
 */
function str_insert($str, $i, $substr) 
{ 
	for($j=0; $j<$i; $j++){ 
		$startstr .= $str[$j]; 
	} 
	for ($j=$i; $j<strlen($str); $j++){ 
		$laststr .= $str[$j]; 
	} 
	$str = ($startstr . $substr . $laststr); 
	return $str; 
}
Copy after login

 


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!