Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.6.0a3

Request #15688 PATHINFO_FILENAME
Submitted: 2009-01-20 07:11 UTC Modified: 2010-08-01 14:29 UTC
From: hm2k Assigned: hm2k
Status: Closed Package: PHP_Compat (version 1.6.0a2)
PHP Version: 5.2.8 OS:
Roadmaps: 1.6.0a3    
Subscription  



Patch php_compat_pathinfo Revisions
Revision 2009-05-01 14:56 UTC
Developer hm2k
 
Download patch

<?php
/**
 * Replace function pathinfo()
 *
 * @category    PHP
 * @package     PHP_Compat
 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
 * @copyright   2004-2009 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>, James Wade <hm2k@php.net>
 * @link        http://php.net/function.htmlspecialchars
 * @author      James Wade <hm2k@php.net>
 * @version     $Revision: 1.0 $
 * @since       PHP 4.0.0
 * @require     PHP 4.0.0 (user_error)
 */

if (!defined('PATHINFO_FILENAME')) {
    define('PATHINFO_FILENAME', 8);
}

function php_compat_pathinfo($path, $options = false)
{
    if (version_compare(PHP_VERSION, '5.2.0', 'ge')) {
        return pathinfo($path, $options);
    }

    // Sanity check
    if (!is_scalar($string)) {
        user_error('pathinfo() expects parameter 1 to be string, ' .
            gettype($string) . ' given', E_USER_WARNING);
        return;
    }

	if ($options & PATHINFO_FILENAME) {
		//bug #15688
		if (strstr($file, '.')) $filename = substr($file,0,strrpos($file,'.'));
		if ($options === PATHINFO_FILENAME) { return $filename; }

		$pathinfo = pathinfo($path, $options);
		$pathinfo['filename']=$filename;
		return $pathinfo;
	}

	return pathinfo($path, $options);

}