Home  >  Article  >  Backend Development  >  How to remove file suffix in php

How to remove file suffix in php

王林
王林Original
2020-07-16 16:20:374032browse

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.

How to remove file suffix in php

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!

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