Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php remove the first digit

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report