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.