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