Home > Article > Backend Development > How to remove file suffix in php
The method to remove the file suffix in php is: you can first use the strrchr() function to find the position of the file suffix in the file name, and then replace the suffix name with the function str_replace(). The str_replace() function returns a string with the replacement value.
You can first use the strrchr() function to find the position of the file suffix in the file name, and then replace the suffix name with the function str_replace().
(Recommended tutorial: php tutorial)
Function introduction:
strrchr() function finds the last occurrence of a string in another string position and returns all characters from that position to the end of the string.
This function returns all characters from the last occurrence of a string in another string to the end of the main string. If the character is not found, returns FALSE.
Function syntax:
strrchr(string,char)
str_replace() function replaces some characters in a string (case sensitive). This function returns a string or array with replacement values.
Function syntax:
str_replace(find,replace,string,count)
Code implementation:
<?php $filename="help.php"; $filename=str_replace(strrchr($filename, "."),"",$filename); echo $filename; //输出help ?>
The above is the detailed content of How to remove file suffix in php. For more information, please follow other related articles on the PHP Chinese website!