How to remove file extension in php?

青灯夜游
Release: 2023-03-06 06:20:02
Original
3127 people have browsed it

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; 
?>
Copy after login

Output:

help
Copy after login

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

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

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!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!