How to replace the first character in php

青灯夜游
Release: 2023-03-08 15:48:01
Original
2084 people have browsed it

In PHP, you can use the substr_replace() function to replace the first character of a string. The syntax format is "substr_replace (specify string object, characters used for replacement, 0, 1)". The substr_replace() function can replace part of a string with another string.

How to replace the first character in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php replace the first character of the string

<?php
$str1 = &#39;hello world!&#39;;
$str2 = substr_replace($str1,&#39;H&#39;,0,1);
print_r($str2);
?>
Copy after login

Output:

Hello world!
Copy after login

[Recommended learning: "PHP Video Tutorial"]

Related function description:

substr_replace() function replaces part of a string with another string. Syntax:

substr_replace(string,replacement,start,length)
Copy after login

How to replace the first character in php

Note: If the start parameter is a negative number and length is less than or equal to start, then length is 0.

Return value: Returns the replaced string. If string is an array, the array is returned.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of How to replace the first character in php. For more information, please follow other related articles on the PHP Chinese website!

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