Skip to content

Instantly share code, notes, and snippets.

@dusta
Created April 8, 2017 08:46
Show Gist options
  • Save dusta/7035d03d3588ea5e78d86c949121c6ba to your computer and use it in GitHub Desktop.
Save dusta/7035d03d3588ea5e78d86c949121c6ba to your computer and use it in GitHub Desktop.
Function returnig the path to a folder and a file
<?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