Get File Refer Without File Extension Inward Php
Definition in addition to Usage - basename()
The basename() component division returns the filename from a path.
Syntax
Example
You convey to know the extension to take it inwards advance though.
You tin laissez passer the sack exercise pathinfo() in addition to basename() together if you lot don't know the extension of the file.
First cash inwards one's chips the extension using pathinfo(), in addition to exercise the basename function, similar this:
pathinfo() returns data nearly path: either an associative array or a string, depending on options.
2. If the path does non convey an extension, no extension chemical constituent volition hold out returned.
Ref: http://www.w3schools.com/php/func_filesystem_basename.asp and http://de.php.net/manual/en/function.pathinfo.php Sumber http://developer-paradize.blogspot.com
The basename() component division returns the filename from a path.
Syntax
basename(path,suffix)
Parameter | Description |
---|---|
path | Required. Specifies the path to check |
suffix | Optional. Specifies a file extension. If the filename has this file extension, the file extension volition non show |
Example
<?php
$path = "/testweb/home.php";
//Show filename amongst file extension
echo basename($path) ."<br/>";
//Show filename without file extension
echo basename($path,".php");
?>
$path = "/testweb/home.php";
//Show filename amongst file extension
echo basename($path) ."<br/>";
//Show filename without file extension
echo basename($path,".php");
?>
The output of the code inwards a higher identify volition be:
home.php
home
home
You convey to know the extension to take it inwards advance though.
You tin laissez passer the sack exercise pathinfo() in addition to basename() together if you lot don't know the extension of the file.
First cash inwards one's chips the extension using pathinfo(), in addition to exercise the basename function, similar this:
$path = "/testweb/home.php"; $ext = pathinfo($path, PATHINFO_EXTENSION); $file = basename($path, ".".$ext); // $file is laid to "home"
Definition in addition to Usage - pathinfo()pathinfo() returns data nearly path: either an associative array or a string, depending on options.
Note:
1. If the path has to a greater extent than than i an extension, PATHINFO_EXTENSION returns exclusively the terminal i in addition to PATHINFO_FILENAME exclusively strips the terminal one.2. If the path does non convey an extension, no extension chemical constituent volition hold out returned.
Ref: http://www.w3schools.com/php/func_filesystem_basename.asp and http://de.php.net/manual/en/function.pathinfo.php Sumber http://developer-paradize.blogspot.com
Comments
Post a Comment