[CODE:]
//第一个
$abc = "asdflkjlkasd.jpg";
$patterns = "/\.[a-zA-Z0-9]{3,4}/i";
$abc = preg_replace($patterns,"",$abc);
echo $abc."
";
//第二个
$abc = "asdflkjlkasd.jpgaaaa";
$abc = pathinfo($abc);
print_r($abc);
echo "
";
//第三个
$abc = "asdflkjlkasd.jpgaaaa";
echo strrchr($abc, ".")."
";
echo substr(strrchr($abc, "."), 1)."
";
//第四个
$abc = "asdflkjlkasd.jpg";
$patterns = "/\.([a-zA-Z0-9]{3,4})$/i";
if(preg_match($patterns,$abc,$ms)){
print_r($ms);
}
echo "
";
//第五个
$abc = "asdflkjlkasd.jpg";
$ps=split("\.",$abc);
$abc=$ps[count($ps)-1];
echo $abc."\n";
//第六个
$abc = "asdflkjlkasd.jpg";
$p = '/\.[a-z0-9]+$/i';
preg_match_all($p, $abc, $result);
print_r($result[0][0]);
?>
结果
第一个:
asdflkjlkasd
第二个:
Array (
[dirname] => .
[basename] => asdflkjlkasd.jpgaaaa
[extension] => jpgaaaa
[filename] => asdflkjlkasd
)
第三个:
.jpgaaaa
jpgaaaa
第四个:
Array ( [0] => .jpg [1] => jpg )
第五个:
jpg