字符串最后一个字符是什么?

比如http://www.csdn.net/
最后一个字符是/
---------------------------------------------------------------

$str = "http://www.csdn.net/";
if(substr($str,-1) == "/")
$str .= "index.php";

用正则表达式,可写作
$str = "http://www.csdn.net/";
echo ereg_replace("/$","/index.php",$str);

Published At
Categories with Web编程
Tagged with
comments powered by Disqus