Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php remove the first digit

Shulou Source: shulou.com Published: 2022-05-31 20:22:13 09月21日 Update

This article mainly explains "how to remove the first digit in php". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to remove the first digit in php.

Removal method: 1, use the substr_replace () function to replace the first digit with an empty string, syntax "substr_replace ($num,", 0 num,1 1) "; 2, use substr to intercept all characters starting from the second digit, syntax" substr ($character) ".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, give you a long list of values, such as "123456789", how to remove the first digit "1", that is, return "23456789" ni?

In fact, PHP provides a variety of solutions, the following article introduces you to two methods.

Method 1: use the substr_replace () function

The substr_replace () function replaces part of a string with another string.

Substr_replace (string,replacement,start,length)

When the replacement value replacement parameter is set to the empty string'', the substring can be deleted.

To remove the first digit, you need to set the replacement position start to 0 and the number of substitutions lengths to 1.

Implementation example:

Method 2: use the substr function

The substr () function can intercept characters of a certain length from a specified position in a string.

Substr (string, start, length)

When the intercept position start is set to 1 and the intercept length length is omitted, all remaining characters can be intercepted from the string index 1 (the second character), and the first digit can be deleted.

Implementation example:

Thank you for reading, the above is the content of "how to remove the first digit of php". After the study of this article, I believe you have a deeper understanding of how to remove the first digit of php, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Characters numbers functions methods strings positions learning content articles examples empty characters syntax length number functions parameters multiple that is ideas situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Apple MariaDB Microsoft