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

How to remove the suffix in php

藏色散人
藏色散人Original
2020-07-24 10:13:024746browse

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.

How to remove the suffix in php

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!

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