Home > Backend Development > PHP Problem > How to remove file suffix in php

How to remove file suffix in php

王林
Release: 2023-03-02 15:52:01
Original
4172 people have browsed it

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)
Copy after login

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)
Copy after login

Code implementation:

<?php 
$filename="help.php"; 
$filename=str_replace(strrchr($filename, "."),"",$filename); 
echo $filename;  //输出help
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template