How to remove the first number in data in php

青灯夜游
Release: 2023-03-15 19:48:01
Original
1935 people have browsed it

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

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

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!

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