Today, I want to deal with the subcharacters that were added due to mistakes, such as linzimu.apk.apk.
At first, rtrim was used. In fact, this function is derived from trim, trim is used to remove the final part, rtrim is used to remove the end of the character, and ltrim is used to remove the character header.
Use the following code:
[Php]
$ Out = rtrim(inin,'.apk ');
$ Out = rtrim(inin,'.apk ');
The output result is linzimu. Well, I want to [php] view plaincopyprint?
$ Out. = '.apk'
$ Out. = '.apk'
That's what I want.
After that, we should check whether the file exists before uploading it to the server. The result is that 4 K of data does not exist.
I finally found the cause after searching for a long time. In fact, I did not read the PHP manual carefully.
Ltrim is followed by charlist instead of $ substring
That is to say, the character list is not necessarily followed by this order,
For example, a in linzimua, apk, and apk will be removed.
The principle of removal is that all the matching operations are always removed until the first non-matching occurs.
So you can use another method immediately.
Train of Thought 1: The thought can be changed to remove the string, can be changed to replace the string, replace with NULL
Use
[Php]
Substr_replace ($ test, '',-4 );
Substr_replace ($ test, '',-4 );
Idea 2: You can also extract the desired string as a sub-string.
[Php]
$ Test = "lin.apk.apk ";
Preg_match ("# ^ (. +) \. (. +) \. # I", $ test, $ m );
Echo $ m [1];