You can use the substr() function in PHP to remove the first character of a string. The syntax is "substr(string,start,length)", just set the start parameter to "1". For example, "substr("Hello world",1)" removes the leading character "h".
Example: php removes the first character of the string
<?php echo substr("Hello world",1); ?>
Running result:
ello world
Description:
The substr() function returns a part of the string.
Note: If the start parameter is negative and length is less than or equal to start, length is 0.
Syntax
substr(string,start,length)
Parameters
string Required. Specifies a part of the string to be returned.
start Required. Specifies where in the string to begin.
Positive number - starts at the specified position in the string
Negative number - starts at the specified position from the end of the string
0 - Start at the first character in the string
length optional. Specifies the length of the string to be returned. The default is until the end of the string.
Positive number - Return from the position of the start parameter
Negative number - Return from the end of the string
Return value: Returns the extracted part of the string, returns FALSE if it fails, or returns an empty string.
In PHP 5.2.2 to 5.2.6 versions, if the start parameter indicates a negative truncation or an out-of-bounds position, FALSE is returned. Other versions get the string starting at the start position.
Recommended related tutorials: PHP tutorial!
The above is the detailed content of How to remove the first character of a string in php?. For more information, please follow other related articles on the PHP Chinese website!