Implementation method: 1. Use substr(), the syntax "substr("data value", 1)"; 2. Use preg_replace() with regular expressions, the syntax "preg_replace('/^./' , '',"data value")", searches for the first character of the specified data and replaces it with a null character.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Remove the first number in the data, and Just remove the first character of the data. Two methods are introduced below
Method 1: Use the substr() function
The substr() function can intercept all characters after the first character to achieve removal The first character of the numeric string.
<?php $num = 1234567; echo substr($num, 1); ?>
Method 2: Use the preg_replace() function with regular expressions
Use regular expressions to search for the digit string One character, replace it with an empty character
<?php $num = 1234567; echo preg_replace('/^./', '', $num); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove the first number in data in php. For more information, please follow other related articles on the PHP Chinese website!