Home >Backend Development >PHP Problem >How to remove the first character in php

How to remove the first character in php

青灯夜游
青灯夜游Original
2021-03-30 19:14:153725browse

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.

How to remove the first character in php

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(&#39;content-type:text/html;charset=utf-8&#39;);
$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)

How to remove the first character in php

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!

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