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 to delete the last two characters of a php string

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to delete the last two characters of php string". In daily operation, I believe many people have doubts about how to delete the last two characters of php string. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to delete the last two characters of php string". Next, please follow the editor to study!

Methods: 1, using substr (), syntax "substr (string, 0mam talk 2)"; 2, using substr_replace (), syntax "substr_replace (string,"-2d2) "; 3, using rtrim (), syntax" rtrim (string, "character") ".

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

Two characters after php string deletion

1. Use the substr () function

The substr () function can intercept a certain length of character from a specified position of a string, which can be called a "substring" or "substring".

You only need to set the second parameter of the function to 0 and the third parameter to-2 to delete the last two characters.

Example:

2. Use the substr_replace () function

The substr_replace () function is used to replace part of a string with another string, starting at a specified location.

When the replacement value (the second parameter) is set to the empty character'', the start position is set to-2 and the number of substitutions is set to 2 to delete the last two characters.

Example:

3. Use the rtrim () function

The rtrim () function removes white space characters or other predefined characters from the end of the string.

You only need to set the second parameter of the function to delete the substring (the last two characters).

Example:

At this point, the study of "how to delete the last two characters of a php string" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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