Home >Backend Development >PHP Problem >How to remove the first number in data in php

How to remove the first number in data in php

青灯夜游
青灯夜游Original
2022-04-24 16:47:091958browse

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.

How to remove the first number in data in php

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);
?>

How to remove the first number in data in php

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(&#39;/^./&#39;, &#39;&#39;, $num);
?>

How to remove the first number in data in php

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!

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