Created
May 20, 2012 20:55
-
-
Save apphp-snippets/2759502 to your computer and use it in GitHub Desktop.
You may retrieve all needed file path data using PHP's built-in function pathinfo. You don't need to create your own functions or use regular expressions to get this info. It was already been created for this purpose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* Source: http://www.apphp.com/index.php?snippet=php-get-remote-ip-address */ | |
| // pathinfo() constants parameter list | |
| // PATHINFO_DIRNAME => directory name | |
| // PATHINFO_BASENAME => name of file (w/out extension) | |
| // PATHINFO_EXTENSION => file extension | |
| // PATHINFO_FILENAME => file name w/ extension | |
| $path = '/images/thumbs/my_avatar.gif'; | |
| //outputs '/images/thumbs/' | |
| echo pathinfo($path, PATHINFO_DIRNAME); | |
| //outputs 'my_avatar' | |
| echo pathinfo($path, PATHINFO_BASENAME); | |
| //outputs 'my_avatar.gif' | |
| echo pathinfo($path, PATHINFO_FILENAME); | |
| //outputs 'gif' | |
| echo pathinfo($path, PATHINFO_EXTENSION); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment