Search This Blog

Loading...

Tuesday, November 8, 2011

PHP: extract filename from a full path string

Easily return the filename component of a path with the built-in PHP basename() function. Useful for splitting a string path to get the filename.


code snippet:
<?php 
$path 
"/home/httpd/html/index.php"$file basename($path);        // $file is set to "index.php" $file basename($path".php"); // $file is set to "index" ?>

notes:
this example from the php.net documentation

0 comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails