PHPにこの関数があるとします
<?php
function get_filename_parts($fname){
/*
receives a filename and returns an array with the filename & extension
example:
receives: myfile1.jpg
returns: array('filename' => 'myfile1', 'extension' => 'jpg')
receives: myfile1.blah.blah.jpg
returns: array('filename' => 'myfile1.blah.blah', 'extension' => 'jpg')
*/
$name_no_ext = explode('.',$fname);
$ext = array_pop($name_no_ext);
$name_no_ext = implode('.',$name_no_ext);
$retval = array('filename' => $name_no_ext, 'extension' => $ext);
return $retval;
}
?>
単一のステートメントでこのようなことを行う構文はありますか:
<?php echo get_filename_parts('test.txt')->filename; ?>
それ以外の:
<?php $fname = get_filename_parts('test.txt'); echo $fname['filename']; ?>
ありがとう!