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
basename(path,suffix)

ParameterDescription
pathRequired. Specifies the path to check
suffixOptional. 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");
?>
The output of the code inwards a higher identify volition be:
home.php
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

Popular posts from this blog

Removing The Index.Php File From Url Inward Codeigniter

What Are The Main Components of a Computer System

Delete Daily Doppler E-Mail Spam From An Iphone [Fix]