Skip to content

Instantly share code, notes, and snippets.

@marceloxp
Last active June 13, 2016 18:45
Show Gist options
  • Save marceloxp/5775606 to your computer and use it in GitHub Desktop.
Save marceloxp/5775606 to your computer and use it in GitHub Desktop.
Captura um nome de arquivo de devolve um array de 2 elementos com o nome e extensão.
<?
function GetFileParts($file_name)
{
$tmp = explode("/", $file_name);
$_filename = array_pop($tmp);
$tmp = explode(".", $_filename);
$ext = array_pop($tmp);
$fil = substr($_filename, 0, ((strlen($ext)+1) * -1));
$r = array();
$r["name"] = $fil;
$r["ext"] = $ext;
return $r;
}
$arquivo = "/folder/subfolder/nomedoarquivo.inc.php";
echo $arquivo . "<br/>";
echo "<pre>";
print_r(GetFileParts($arquivo));
echo "</pre>";
?>
nomedoarquivo.inc.php
Array
(
[name] => nomedoarquivo.inc
[ext] => php
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment