Today I would like to deal with the previous sub-characters, such as linzimu.apk.apk, which were added due to errors.
Originally used is rtrim, in fact this function is the derivative of trim, trim is to remove the finishing touches, and RTrim is to remove the end of the character, there is a removal of the character head is LTrim.
Use the following code:
[PHP]
$out = RTrim ($in, '. apk ');
$out = RTrim ($in, '. apk ');
The result of the output is linzimu, well I guess, then I'll just go straight to [PHP] view plaincopyprint?
$out. = '. apk '
$out. = '. apk '
That's what I want.
Later on, it is safe to check if the file exists before uploading the server. Results 2W more data, there is 4k does not exist.
Find a half-day finally found the reason, in fact, I did not see the PHP manual.
Behind the LTrim is charlist, not $substring.
That is, the character list is not necessarily in this order,
For example, a in linzimua,apk,apk will be removed.
The principle of removal is that the match has been removed until the first mismatch is known.
So instead of using another method, you can use the
Idea 1: Can change the mind 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 change the string you want as a substring.
[PHP]
$test = "lin.apk.apk";
Preg_match ("#^ (. +) \. (. +)) \ #i ", $test, $m);
echo $m [1];
http://www.bkjia.com/PHPjc/477396.html www.bkjia.com true http://www.bkjia.com/PHPjc/477396.html techarticle today I would like to deal with the previous sub-characters, such as linzimu.apk.apk, which were added due to errors. Originally used is rtrim, in fact this function is a trim derivative, trim is to remove the finishing touches, and RTrim is to go ...