The code that intercepts the string of PHP strings in disguise

Source: Internet
Author: User
Very extreme examples, a disguised solution to the problem of thinking, recorded, for later use.
How do I remove the suffix of a file's default name?
$fileName = A.txt
Two methods:
1: Borrow PHP's Strrchr+trim method: STRRCHR (STRING1,STRING2) returns the part of string1 from the last start to the first encounter with string2, along with string2.
Suffix general. XXX, so you can $str1 = STRRCHR ($fileName, ".");
if ($str 1) {
$fileName = Trim ($fileName, $str 1);
}
2: Borrowing PHP's Strrpos+substr method: Strrpos (STRING1,STRING2) returns the last location string2 in string1, substr (string1,num1,num2) Intercepts a string of string1 from NUM1 to num2.
Also with the help of "."
$pos = Strrpos ($fileName, ".");
if ($pos) {
$fileName = substr ($fileName, 0, $pos);
}
This is a very extreme example, and it is not very meticulous in the event that the name $filename = a.b.c.d, and no suffix will be processed as well:)

The above describes the interception string PHP string in the form of subtraction code, including the interception of string content, I hope that the PHP tutorial interested in a friend helpful.

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