Skip to content

Instantly share code, notes, and snippets.

@1000k
Created September 4, 2012 01:55
Show Gist options
  • Save 1000k/3615690 to your computer and use it in GitHub Desktop.
Save 1000k/3615690 to your computer and use it in GitHub Desktop.
Frequently-appearing phrases which relate to paths.
<?php
// Frequently-appearing phrases which relate to paths.
$paths = array(
array('__FILE__', __FILE__),
array('realpath(__FILE__)', realpath(__FILE__)),
array('dirname(__FILE__)', dirname(__FILE__)),
array('basename(__FILE__)', basename(__FILE__)),
array('pathinfo(__FILE__)', pathinfo(__FILE__)),
array('__DIR__', __DIR__),
);
foreach ($paths as $row) {
echo "{$row[0]}:\t";
if (is_array($row[1])) {
print_r($row[1]);
} else {
echo "{$row[1]}\n";
}
}
@1000k
Copy link
Author

1000k commented Sep 4, 2012

If you put this script in C:\work\htdocs\sandbox\paths.php, for example, the result is following:

$ cd c:\work\htdocs\sandbox
$ php paths.php
__FILE__:       C:\work\htdocs\sandbox\paths.php
realpath(__FILE__):     C:\work\htdocs\sandbox\paths.php
dirname(__FILE__):      C:\work\htdocs\sandbox
basename(__FILE__):     paths.php
pathinfo(__FILE__):     Array
(
    [dirname] => C:\work\htdocs\sandbox
    [basename] => paths.php
    [extension] => php
    [filename] => paths
)
__DIR__:        C:\work\htdocs\sandbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment