Home  >  Article  >  Backend Development  >  PHP code PHP code that inserts a string at the specified position of the string

PHP code PHP code that inserts a string at the specified position of the string

WBOY
WBOYOriginal
2016-07-29 08:41:551321browse

Copy code The code is as follows:


//Insert a string
function str_insert($str, $i, $substr)
{
for($j=0; $j<$i; $j++ ){
$startstr .= $str[$j];
}
for ($j=$i; $j$laststr .= $str[$j];
}
$str = ($startstr . $substr . $laststr);
return $str;
}


Popularity: 3%

The above introduces the PHP code to insert a string of PHP code at the specified position of the string, including the content of PHP code. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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