Home > Article > Backend Development > How to remove the suffix in php
How to remove the suffix in php: First create a PHP sample file; then obtain the file whose suffix needs to be removed; finally remove the suffix through the "str_replace" and "strrchr" functions.
Recommended: "PHP Tutorial"
php remove file name suffix (extension):
<?php $filename="help.php"; $filename=str_replace(strrchr($filename, "."),"",$filename); echo $filename; ?>
Output:
help
Related introduction:
str_replace() function replaces some characters in a string (case sensitive).
strrchr() function (in PHP) finds the position of the first occurrence of a character starting from the right in the specified string. If successful, returns the character and the characters following it. If it fails, returns NULL. Corresponding to this is the strchr() function, which searches for the first occurrence of a specified character in a string and the characters that follow it.
The above is the detailed content of How to remove the suffix in php. For more information, please follow other related articles on the PHP Chinese website!