很多时候需要获取某个字符串的后缀名,比如文件的后缀名,或者用某个符号分割的一个字符串。
有个函数很好用
string strrchr ( string $haystack , mixed $needle )
官方文档看这里
例子:
<?php
$path = '/www/public_html/index.html';
$filename = substr(strrchr($path, "/"), 1);
echo $filename; // "index.html"
?>
应该就很好懂了吧