@H_502_0@
操作文件
@H_502_0@1.使用5种以上的方式获取一个文件的扩展名
@H_502_0@要求: dir/upload.image.jpg,找出.jpg或者jpg
<div class="jb51code">
<pre class="brush:PHP;">
<?PHP
/**
$str = "dir/upload.image.jpg";
function one ($str)
{
$arr = explode('.',$str);
$count = count($arr);
return $arr[$count - 1];
}
function two ($str)
{
$len = strlen($str);
for ($i = $len - 1,$name = ''; $str[$i] != '.'; $i --) {
$name .= $str[$i];
}
$name = strrev($name);
return $name;
}
function three($str)
{
$path = pathinfo($str);
return $path['extension'];
}
function four($str)
{
$arr = explode('.',$str);
return array_pop($arr);
}
function five($str)
{
$start = strrpos($str,'.');
return substr($str,$start + 1);
}
echo one($str);
echo "
";
echo two($str);
echo "
";
echo three($str);
echo "
";
echo four($str);
echo "
";
echo five($str);
echo "
";