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

How to delete the first character in php string

藏色散人
Release: 2023-03-02 08:00:01
Original
5204 people have browsed it

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;
Copy after login

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);
Copy after login

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');
Copy after login

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!

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