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

PHP中文网
Release: 2023-02-28 20:36:01
Original
1904 people have browsed it

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;
}
?>
Copy after login

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

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