note 56469 deleted from function.substr by bobby

From: Date: Thu, 14 Sep 2006 17:42:29 +0000
Subject: note 56469 deleted from function.substr by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117183@lists.php.net to get a copy of this message
Note Submitter: andrzej dot martynowicz at gmail dot com ---- substr() can provide easy way to get a filename with or without extension <? function getFilename( $file, $extension = true ) { return ($extension || false === $dot = strrpos( basename( $file ), '.' )) ? basename( $file ) : substr( basename( $file ), 0, $dot ); } echo getFilename( 'foo.php' ); // foo.php echo getFilename( 'foo.php', false ); // foo echo getFilename( 'dir/foo.php' ); // foo.php echo getFilename( 'foo' ); // foo - note that $extension is true here echo getFilename( '.php', false ); // '' - empty string ?>

« previous php.notes (#117183) next »