Thursday 18 November 2010

PHP to get current file name without the extension

This little function will return the file name which calls it minus the .php extension.

<?php

function getCurrentFile()
{
    $currentFile = $_SERVER["SCRIPT_NAME"];
    $parts = Explode('/', $currentFile);
    $currentFile = substr($parts[count($parts) - 1],0,-4);
    return $currentFile;
}
?>

No comments:

Post a Comment