Php deletes the substring at the end of the string, deletes the Start character, and deletes the character at both ends _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php deletes the child character at the end of the string, deletes the Start character, and deletes the two characters at both ends. The following problem is encountered when processing the specific characters at both ends of the string to be deleted. first look at the example SPANakmumuwritedb. json; what I want to do is to start deletion. today, when processing specific characters at both ends of the string to be deleted, I encountered the following problem. let's look at the example first.

$ Str = 'akmumu/writedb. json ';
What I want to do is to delete the starting akmumu and then delete the. json at the end, so that only useful characters/writedb are retained.
Start the ltrim I used to delete akmumu, and then use rtrim to delete. json
The result shows that I understand the trim error. the trim parameters are as follows:
Rtrim (string, charlist)
This parameter is charlist, that is, it is not necessarily searched in order. for example
$ Str = 'akmumu/writedbsojn. json ';
The result is still/write. The/writedbsojn that I want does not appear. that is to say, as long as any character in the charlist matches, this will continue...
So I used something else.
Str_replace, substr_replace.
For security, code is added to prevent the interception of errors.

The 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 );
}
}
}


In this way, you can

Required SPAN style = FONT-SIZE: 18px/SPAN $ str = 'akmumu/writedb. json'; what I want to do is to start deleting...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.