PHP Delete String End Sub-character _php tutorial

Source: Internet
Author: User
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 ...

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