Get the App
SLTechnology News&Howtos  ›  Development  › 

How php gets or deletes the last few characters

Shulou Source: shulou.com Published: 2022-05-31 18:16:59 09月22日 Update

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!

Tags: Characters functions strings parameters statements three number content negative values learning practical deeper interest right practical practical simple operation tutorials methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info OPPO Reno Huawei macOS