Req #69385 [NEW]: Add glob_get_base_path() function
| From: | bschussek at gmail dot com | Date: | Mon, 06 Apr 2015 14:05:44 +0000 |
| Subject: | Req #69385 [NEW]: Add glob_get_base_path() function | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-191847@lists.php.net to get a copy of this message | ||
From: bschussek at gmail dot com
Operating system:
PHP version: 5.6.8RC1
Package: Filesystem function related
Bug Type: Feature/Change Request
Bug description:Add glob_get_base_path() function
Description:
------------
I'd love to see a glob_get_base_path() function that returns the base
path of a glob following the rules used by glob().
The base path is the most specific directory path of a glob. Knowing the
base path is useful when mapping a glob to a target directory. This
mapping can be used, for example, to copy the matched files to the
directory.
Signature:
glob_get_base_path(string $glob[, int $flags = 0])
$glob - a glob
$flags - the glob() flags
Result: string - the base path of the glob
Usage example:
<?php
// could be stored in the application configuration
define('SOURCE_GLOB', 'css/*.css');
define('TARGET_DIR', 'public_html/css');
// runtime
$basePath = glob_get_base_path(SOURCE_GLOB);
$basePathLength = strlen($basePath);
foreach (glob($glob) as $sourcePath) {
$targetPath = substr_replace($sourcePath, TARGET_DIR, 0,
$basePathLength);
copy($sourcePath, $targetPath);
}
Test script:
---------------
<?php
echo glob_get_base_path('*.css')."\n";
echo glob_get_base_path('/*.css')."\n";
echo glob_get_base_path('css/*.css)."\n";
echo glob_get_base_path('css/foo*.css)."\n";
echo glob_get_base_path('css/foo{bar,baz}.css)."\n";
Expected result:
----------------
.
/
css
css
css
--
Edit bug report at https://bugs.php.net/bug.php?id=69385&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69385&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69385&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69385&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69385&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69385&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69385&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69385&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69385&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69385&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69385&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69385&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69385&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69385&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69385&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69385&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69385&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69385&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69385&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69385&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69385&r=mysqlcfg