Home >Backend Development >PHP Problem >How to remove the first character in php
In PHP, you can use the substr() function to remove the first character of a string. The syntax format is "substr("String",1)". The substr() function is used to return a part of a string. When the value of the second parameter is 1, it means that the return starts from the second character of the string, and the first character can be removed.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php removes the first part of the string characters
In PHP, you can use the substr() function to remove the first character of a string.
Example:
<?php header('content-type:text/html;charset=utf-8'); $str="Hello world!"; echo "原字符串:",$str,"<br>"; $str2=substr($str,1); echo "去掉第一个字符后的字符串:",$str2,"<br>"; ?>
Output:
原字符串:Hello world! 去掉第一个字符后的字符串:ello world!
Related function introduction:
substr() function returns a string a part of. The syntax is as follows:
substr(string,start,length)
Description: If the start parameter is a negative number and length is less than or equal to start, length is 0.
Return value: Returns the extracted part of the string, returns FALSE if it fails, or returns an empty string.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove the first character in php. For more information, please follow other related articles on the PHP Chinese website!