Php character strings in disguise subtraction code _ php skills
Source: Internet
Author: User
An extreme example of codes whose php strings are reduced in disguise is a disguised solution that 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 :)
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.