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

How to remove the suffix in php

藏色散人
Release: 2023-03-03 08:22:01
Original
4867 people have browsed it

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

Output:

help
Copy after login

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!

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