很多時候需要獲取某個字符串的後綴名,比如文件的後綴名,或者用某個符號分割的一個字符串。
有個函數很好用
string strrchr ( string $haystack , mixed $needle )
官方文檔看這裏
例子:
<?php
$path = '/www/public_html/index.html';
$filename = substr(strrchr($path, "/"), 1);
echo $filename; // "index.html"
?>
應該就很好懂了吧