Home > Article > Backend Development > How to delete the first character in php string
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.
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!