In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the "php how to delete the end of the string subcharacters, delete the start character, delete both ends of the character" related knowledge, in the actual case of the operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
Today, when dealing with deleting specific characters at both ends of a string, we encounter the following problems. Let's take a look at the example first.
$str = 'akmumu/writedb.json'
All I have to do is delete the initial akmumu and then delete the .json at the end, so that only the useful character / writedb remains
First I use ltrim to delete akmumu, and then use rtrim to delete .json
It turns out that I misunderstood trim. The parameters of trim are as follows.
Rtrim (string,charlist)
His parameter is charlist, that is, it may not be looked up in order, for example, I give a
$str = 'akmumu/writedbsojn.json'
The result is still / write, and the / writedbsojn I want doesn't appear, which means it will go on as long as any character in the charlist matches.
So I used something else.
Str_replace,substr_replace is fine.
For security reasons, code has been added to prevent further interception of errors
The copy code is as follows:
If (strpos ($str,'akmumu/')! = = FALSE
$str = substr ($str,7)
If (strpos ($str,'.json')! = = FALSE)
{
If (substr ($str,-5,5) = = '.json')
{
$str = substr_replace ($str,'',-5)
}
}
}
That's it.
This is the end of how to delete the subcharacters at the end of the string, delete the start characters, and delete the characters at both ends of the string in php. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.