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...