如何在获取文件扩展名的同时保留文件名中的句点?我正在分解字符串以获取文件扩展名,但文件名中的所有点也都消失了。
$description = '';
$file = "Another Magazine. photos by joe smith. girl_brunette_headband.jpg";
$file = explode('.',$file);
$extension = end($file);
$num_rows = count($file);
$j=0;
while($j<=$num_rows){
$description .= $file[$j];
$description = preg_replace("/$extension/", '', $description);
$j++;
}
echo $description;// outputs: Another Magazine photos by joe smith girl_brunette_headband
我想要的输出是:另一本杂志。乔·史密斯的照片。girl_brunette_headband
要获得文件名(即基名w/o扩展名em>文档功能:
$description = pathinfo($file, PATHINFO_FILENAME);
要获得扩展,它是类似的:
$ext = pathinfo($file, PATHINFO_EXTENSION);
ehmecho substr($file, 0, strrpos($file, '.'));