Php character strings in disguise subtraction code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php strings in disguise. An extreme example is a disguised solution. it is recorded for future use. How do I remove the suffix of the default file name? $FileNamea.txt can be used in two ways: 1. a very extreme example of using php, a disguised solution, is recorded for future use.
How do I remove the suffix of the default file name?
$ FileName = a.txt
Two methods:
1: Use the strrchr + trim method of php: strrchr (string1, string2) to return the part from the end of string1 to the first occurrence of string2, together with string2.
The suffix is generally. XXX, so $ str1 = strrchr ($ fileName ,".");
If ($ str1 ){
$ FileName = trim ($ fileName, $ str1 );
}
2: Use the strrpos + substr method of php: strrpos (string1, string2) to return the last position of string2 in string1, substr (string1, num1, num2) truncates string1 string from num1 to num2.
With the help "."
$ Pos = strrpos ($ fileName ,".");
If ($ pos ){
$ FileName = substr ($ fileName, 0, $ pos );
}
This is an extreme example, and the processing is not very careful. if the name $ fileName = a. B. c. d is not suffixed, it will be processed as well :)

Bytes. How do I remove the suffix of the default file name? Using filename.txt two methods: 1: borrow php...

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.