Home > Backend Development > PHP Tutorial > 一个取得文件扩展名的php函数_PHP

一个取得文件扩展名的php函数_PHP

WBOY
Release: 2016-06-01 12:39:21
Original
767 people have browsed it

<font color="#000000"> <font color="#0000BB"></font><font color="#007700"> <br></font><font color="#FF8000">/*<br>GetFileType <br>用法:GetFiletype($filename)<br>*/ <br></font><font color="#007700">function </font><font color="#0000BB">GetFiletype</font><font color="#007700">(</font><font color="#0000BB">$Filename</font><font color="#007700">) {    <br>    if (</font><font color="#0000BB">substr_count</font><font color="#007700">(</font><font color="#0000BB">$Filename</font><font color="#007700">, </font><font color="#DD0000">"."</font><font color="#007700">) == </font><font color="#0000BB">0</font><font color="#007700">) {    </font><font color="#FF8000">// 检查文件名中是否有.号。 <br><br><br>    </font><font color="#007700">return;        </font><font color="#FF8000">// 返回空<br><br><br>    </font><font color="#007700">} else if (</font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$Filename</font><font color="#007700">, -</font><font color="#0000BB">1</font><font color="#007700">) == </font><font color="#DD0000">"."</font><font color="#007700">) {    </font><font color="#FF8000">// 检查是否以.结尾,即无扩展名 <br><br><br>    </font><font color="#007700">return;        </font><font color="#FF8000">// 返回空 <br><br><br>    </font><font color="#007700">} else { <br><br><br>    </font><font color="#0000BB">$FileType </font><font color="#007700">= </font><font color="#0000BB">strrchr </font><font color="#007700">(</font><font color="#0000BB">$Filename</font><font color="#007700">, </font><font color="#DD0000">"."</font><font color="#007700">);    </font><font color="#FF8000">// 从.号处切割<br><br><br>    </font><font color="#0000BB">$FileType </font><font color="#007700">= </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$FileType</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);    </font><font color="#FF8000">// 去除.号 <br><br><br>    </font><font color="#007700">return </font><font color="#0000BB">$FileType</font><font color="#007700">;    </font><font color="#FF8000">// 返回 <br><br><br>    </font><font color="#007700">} <br><br><br>} <br><br><br></font><font color="#0000BB">$Filename </font><font color="#007700">= </font><font color="#DD0000">"Testfilename.php4"</font><font color="#007700">; <br><br><br></font><font color="#0000BB">$Filename </font><font color="#007700">= </font><font color="#0000BB">GetFileType</font><font color="#007700">(</font><font color="#0000BB">$Filename</font><font color="#007700">); <br><br><br>echo </font><font color="#0000BB">$Filename</font><font color="#007700">;    </font><font color="#FF8000">//  打印出php4 <br><br><br></font><font color="#0000BB">?></font></font>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template