PHP
ש: איך אני יכול לדעת סיומת של קובץ מסוים?
ת: על מנת לדעת סיומת של קובץ מסוים נחלק את שם הקובץ למערכים ע"י explode לתו "." .
לאחר מכן נציב בתוך משתנה חדש את את איבר המערך האחרון שיצרנו, לשם כך, נשתמש ב count פחות 1. הקוד הסופי הוא:
PHP קוד:
<?
$file_name = "MyFile.zip.lol.ok.rar.exe.omg.zip.html.jpg";
$file_ext = explode(".",$file_name);
$file_ext = $file_ext[count($file_ext) - 1];
echo "File name is: $file_name<br />File ext is: $file_ext";
?>
דוגמא:
http://www.losnir.net/file_ext.php
קוד מקור:
http://www.losnir.net/file_ext.phps