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 php gets or deletes the last few characters

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

Share

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

This article mainly explains "how to get or delete the last few characters of php". Friends who are interested may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how php gets or deletes the last few characters".

Php can use "substr ($str,-N)" statement to get the final character, and the parameter "N" specifies the number of characters to be read; delete the last character can use "rtrim ($str," specified character ")" statement, or use "substr ($str,0,-N)" statement, the parameter "N" specifies the number of characters to be deleted.

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

Php gets the last few characters

In php, you can use the substr () function to read the last few characters of a string.

The substr () function returns a portion of the string. You only need to omit the third argument of the function and set the second parameter to a negative value (- n), where n specifies the next few characters you want to read

Php deletes the last few characters

1. Use the rtrim () function

The rtrim () function removes white space characters or other predefined characters on the right side of the string.

2. Use the substr () function

The substr () function returns a portion of the string. You just need to set the second parameter of the function to 0, the third parameter to a negative value (- n), and n to specify the next few characters you want to delete.

At this point, I believe you have a deeper understanding of "how php gets or deletes the last few characters". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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