Q:

print (get) file extension in PHP

belongs to collection: PHP Miscellaneous

0

print (get) file extension in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Here, we're going to discuss the PHP pathinfo() function which is useful in getting information about a path. This function returns useful information about a file path including file name, extension, directory, and file base name. The below example explains the usage of pathinfo().

<?php
	$file_data = pathinfo('/path/to/dir/mynewfile.php');
	echo $file_data['basename'], "\n";
	echo $file_data['dirname'], "\n";
	echo $file_data['filename'], "\n";
	//returns the current file extension
	echo $file_data['extension'];
?>

Output

mynewfile.php
/path/to/dir
mynewfile
php

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Miscellaneous

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Include a Class from another file in PHP... >>
<< Getting current date & time in PHP...