Home  >  Article  >  Backend Development  >  How to delete the first character in php string

How to delete the first character in php string

藏色散人
藏色散人Original
2020-07-08 11:10:455160browse

How to delete the first character in a php string: 1. Use the "$str[0] = "";" method; 2. Use the "substr()" function to delete the first character; 3. Use the "ltrim()" function to delete the first character; 4. Use "preg_replace()" to delete the first character.

How to delete the first character in php string

php string delete the first character

The first method: replacement method

$str = "hello";
$str[0] = "";
// $str[0] = false;
// $str[0] = null;

Time to execute 1.000.000 tests: 0.39602184295654 seconds

Second method: Use substr() to delete the first character

$str = "hello";
$str = substr($str, 1);

Execute 1.000.000 Time for 1.000.000 tests: 5.153294801712 seconds Seconds

Fourth method: Use preg_replace() to delete the first character

$str = "hello";
$str= ltrim ($str,'h');

Time to execute 1.000.000 tests: 6.8543920516968 seconds

For more related knowledge, please visit

PHP Chinese website

!

The above is the detailed content of How to delete the first character in php string. 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