Home >Backend Development >PHP Problem >How to remove the first two characters of a string in php
php method to remove the first two characters of a string: 1. Use the substr() function, the syntax "substr($str, 2)"; 2. Use the substr_replace() function, the syntax "substr_replace($str , '', 0,2)”.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php removes strings The first two characters
1. Use the substr() function
The substr() function can intercept a certain length of characters from the specified position of the string. Character, returns the extracted part of the string, returns FALSE on failure, or returns an empty string.
<?php $str = "hello,world"; $str2 = substr($str, 2); echo $str2; ?>
2. Use the substr_replace() function
substr_replace() function to replace part of a string with another string .
<?php $str = "world"; $str2 = substr_replace($str, '', 0,2); echo $str2; ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove the first two characters of a string in php. For more information, please follow other related articles on the PHP Chinese website!