A very extreme example, a way of solving a problem in disguise, recorded for later use.
How to remove the suffix from the default file name?
$fileName = a.txt
Two methods:
1: Borrow PHP’s strrchr+trim method: strrchr(string1, string2) returns the part from the end of string1 to the first encounter with string2, along with string2.
The suffix is generally .XXX, so you can use $str1 = strrchr($fileName,".");
Borrowing php’s strrpos +substr method: strrpos(string1,string2) returns the position of the last occurrence of string2 in string1, substr(string1,num1,num2) intercepts the strings from num1 to num2 in string1.
Also with the help of "."
$pos = strrpos($fileName,".");
if($pos){
$fileName = substr($fileName,0,$pos);
}
This is a very extreme Example, and this processing is not very rigorous. If the name $fileName = a.b.c.d, without a suffix, it will be processed in the same way:)
The above introduces the code for intercepting strings and subtracting strings in disguise in PHP, including the content of intercepting strings. I hope it will be helpful to friends who are interested in PHP tutorials.