Home >Backend Development >PHP Tutorial >PHP string subtraction code in disguised form_PHP tutorial

PHP string subtraction code in disguised form_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-21 15:56:24786browse

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 of string2 , returned together with string2.
The suffix is ​​generally . }
2: Borrow 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 string 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 careful. If the name $fileName = a.b.c.d, without a suffix, it will be processed in the same way:)



http://www.bkjia.com/PHPjc/318095.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318095.htmlTechArticleA very extreme example, a way of solving the problem in disguise, record it for later use. How to remove the suffix from the default file name? $fileName=a.txt Two methods: 1: Borrow php...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn