Home >Backend Development >PHP Problem >How to remove file extension in php?
Removal method: First use strrchr() to return a string in the form of ".suffix name"; then use str_replace() to replace the string in the form of ".suffix name" in the file name with a null character; Syntax "str_replace(strrchr(filename, "."),"",filename);".
##php remove the file suffix
<?php $filename="help.php"; $filename=str_replace(strrchr($filename, "."),"",$filename); echo $filename; ?>Output:
help
##Instructions:Recommendation: "PHP Video Tutorial"
strrchr() function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string.
Syntax:
strrchr(string,char)
Parameters:
##string Required. Specifies the string to be searched for.str_replace(find,replace,string,count)Parameters:
##find Required. Specifies the value to look for.
replace Required. Specifies the value to replace the value in find .
#string Required. Specifies the string to be searched for.
#count Optional. A variable counting the number of substitutions.
The above is the detailed content of How to remove file extension in php?. For more information, please follow other related articles on the PHP Chinese website!