Home  >  Article  >  Backend Development  >  How to remove file name suffix in php

How to remove file name suffix in php

hzc
hzcOriginal
2020-06-23 11:18:002694browse

How to remove file name suffix in php

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

str_replace() Function replaces some characters in a string with other characters (case sensitive).

Syntax str_replace(find,replace,string,count)

This function must follow the following rules:

  • If the searched string is an array, then it will return an array.

  • If the searched string is an array, then it will find and replace each element in the array.

  • If you need to search and replace the array at the same time, and the elements that need to be replaced are less than the number of found elements, then the excess elements will be replaced with empty strings. If the searched is an array, and the replacement is a string, then the replacement string will work on all found values.

Note: This function is case-sensitive. Please use the str_ireplace() function to perform a case-insensitive search.

Note: This function is binary safe.

Recommended tutorial: "php tutorial"

The above is the detailed content of How to remove file name 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