Created
April 8, 2017 08:46
-
-
Save dusta/7035d03d3588ea5e78d86c949121c6ba to your computer and use it in GitHub Desktop.
Function returnig the path to a folder and a file
This file contains 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 | |
/** | |
* Explode patch to folder and file | |
* function pathFile('patch1/patch2/patch3/file1.php') | |
* return array('patch1/patch2/patch3/', 'file1.php') | |
*/ | |
function pathFile($path) { | |
$folder = ''; | |
$name = $path; | |
if(strpos($path, '/')) { | |
$path = explode('/', $path); | |
$pathCount = count($path)-1; | |
$folder = ''; | |
for ($i=0; $i < $pathCount; $i++) { | |
$folder .= $path[$i].'/'; | |
} | |
$name = $path[$pathCount]; | |
} | |
return array($folder, $name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment