Home >Backend Development >PHP Tutorial >A small function that inserts a string at a specified position in the string

A small function that inserts a string at a specified position in the string

PHP中文网
PHP中文网Original
2017-03-25 13:48:141930browse

A small function that inserts a string at a specified position in a string:

<?php
//插入一段字符串
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;
}
?>

The above is the content of a small function that inserts a string at a specified position in a string. For more related content, please pay attention to the PHP Chinese website (www.php .cn)!

Related articles:

php custom interception of Chinese strings - utf8 version

PHP development skills (10) - implementation method of Chinese string interception without garbled characters

Implementing strings through eval in php Detailed explanation of the code for the format calculation formula

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