In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how php deletes the last character after the output". In daily operation, I believe many people have doubts about how to delete the last character after php output. Xiaobian consulted all kinds of information and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to delete the last character after output by php". Next, please follow the editor to study!
Php delete the last character after the output: 1, use the substr and strlen functions to delete the last character; 2, directly use the substr function in reverse order to cut the last character; 3, use rtrim to delete the white space character at the end of the string.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How does php delete the last character after the output?
Summarize three methods for PHP to delete the last character of a string
I. Preface
When select () reads one-to-many information from a database, it is often necessary to split the extracted array with a specific character and then splice it into a string.
Common grammatical formats:
Foreach ($arr as $key = > $value) {2 $arr_str = $arr ['xroomid']. ','. $arr_str;3}
Suppose the characters in the character array $arr are
Arr [0] = 2 arr [1] = 3 arr [2] ='c'
Then, the concatenated $arr_str string is a _
2. Summary of the methods for deleting the last character in PHP:
Method 1:
Substr ($arr_str,0,strlen ($arr_str)-1)
Substr () function syntax: string substr (string $string, int $start [, int $length])
Strlen () function syntax: int strlen (string $string)
The principle of this example:
First use the strlen () function to determine the length of the string $arr_str, and then use the substr () function to intercept $arr_str to the penultimate digit of $arr_str. In this way, the last "," is removed.
Feeling of use:
Not recommended, there are more concise and easy to use ways in php!
Method 2:
Substr ($arr_str, 0,-1)
Directly use the substr () function to cut out the last character in reverse order
Use feeling: it is still very appropriate ~ ~ but first you have to make sure that there must be something in the string, and the last bit must not!
Method 3:
Rtrim ($arr_str, ",")
Rtrim () function syntax: string rtrim (string $str [, string $character_mask])
Rtrim-removes white space characters (or other characters) from the end of a string
Feeling of use:
It is simply prepared for this need!
Note: after the above method operates on the string, it returns the operation result and does not change the string itself! Remember to use a variable to receive the results!
At this point, the study of "how to delete the last character after the php output" 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.