开发者

How to get the extension of a file? PHP command line

I'm making a CLI script that mass renames files, however I do not kno开发者_如何学Gow how to get the extension of a file that I don't know the extension of... Basically the CSV file I have is laid out like so:

"New filename", "oldfile",
"New filename", "oldfile"

No extension is given on the old file. How would I go about doing this? I would greatly appreciate the help.


pathinfo will return an array which includes that information. You're specifically looking for the key 'extension'.

<?php
// from http://php.net/manual/en/function.pathinfo.php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');

echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜