Home >Backend Development >PHP Tutorial >About the method of subtracting strings in disguised form in PHP
This article mainly introduces the disguised string subtraction method in PHP. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
Very extreme example, one Record the ideas for solving problems in disguised form 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, together with string2 Return together.
The suffix is generally . Position, substr(string1,num1,num2) intercepts string1 strings from num1 to num2.
Also with the help of "."
$str1 = strrchr($fileName,"."); if($str1){ $fileName = trim($fileName,$str1); }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. Dropped:)
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
php implementation of converting time difference into string
Use php to implement addition and subtraction verification code
The above is the detailed content of About the method of subtracting strings in disguised form in PHP. For more information, please follow other related articles on the PHP Chinese website!