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

How to remove file extension in php?

青灯夜游
青灯夜游Original
2020-09-27 16:01:393194browse

Removal method: First use strrchr() to return a string in the form of ".suffix name"; then use str_replace() to replace the string in the form of ".suffix name" in the file name with a null character; Syntax "str_replace(strrchr(filename, "."),"",filename);".

How to remove file extension in php?

##php remove the file suffix

<?php 
$filename="help.php"; 
$filename=str_replace(strrchr($filename, "."),"",$filename); 
echo $filename; 
?>

Output:

help

Recommendation: "PHP Video Tutorial"

##Instructions:


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.

Syntax:

strrchr(string,char)

Parameters:

##string Required. Specifies the string to be searched for.
  • #char Required. Specifies the characters to search for. If the argument is a number, then searches for characters matching the numeric ASCII value.
  • str_replace() function replaces some characters in a string (case-sensitive).
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.

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!

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