php method to remove the file suffix: first use the strrchr() function to find the position where the file suffix appears in the file name; then use the str_replace() function to replace the file suffix.
str_replace() function replaces some characters in a string (case sensitive).
(Recommended tutorial: php graphic tutorial)
Syntax:
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.
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.
Grammar:
strrchr(string,char)
(Learning video recommendation: php video tutorial)
Parameters:
<?php $filename="help.php"; $filename=str_replace(strrchr($filename, "."),"",$filename); echo $filename; ?>
help
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!