3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $finfo = new finfo(FILEINFO_MIME_TYPE); $postMimeType = $finfo->buffer(file_get_contents('http://4.bp.blogspot.com/-JOqxgp-ZWe0/U3BtyEQlEiI/AAAAAAAAOfg/Doq6Q2MwIKA/s1600/google-logo-874x288.png')); // If the URL has the file extension included, this will find it $fileExtension = pathinfo('http://4.bp.blogspot.com/-JOqxgp-ZWe0/U3BtyEQlEiI/AAAAAAAAOfg/Doq6Q2MwIKA/s1600/google-logo-874x288.png', PATHINFO_EXTENSION); // Otherwise, get file extension from the MIME type // This is necessary for image thumbnails to display correctly in the WordPress dashboard media section if ($fileExtension === '') { $fileExtension = basename($postMimeType); $filename = $filename . '.' . $fileExtension; } var_dump($fileExtension);
based on ljKN1
Output for 5.3.0 - 5.4.38, 5.5.24 - 5.5.32, 5.5.34 - 5.6.17, 5.6.20 - 5.6.28, 7.0.0 - 7.0.3, 7.0.5 - 7.1.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/rFklb on line 4 Warning: file_get_contents(http://4.bp.blogspot.com/-JOqxgp-ZWe0/U3BtyEQlEiI/AAAAAAAAOfg/Doq6Q2MwIKA/s1600/google-logo-874x288.png): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/rFklb on line 4 string(3) "png"
Output for 5.4.39 - 5.4.45, 5.5.33, 5.6.18 - 5.6.19, 7.0.4
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/rFklb on line 4 Warning: file_get_contents(http://4.bp.blogspot.com/-JOqxgp-ZWe0/U3BtyEQlEiI/AAAAAAAAOfg/Doq6Q2MwIKA/s1600/google-logo-874x288.png): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/rFklb on line 4 string(3) "png"
Output for hhvm-3.10.0 - 3.12.0
Warning: Failed to open http://4.bp.blogspot.com/-JOqxgp-ZWe0/U3BtyEQlEiI/AAAAAAAAOfg/Doq6Q2MwIKA/s1600/google-logo-874x288.png (Could not resolve host: 4.bp.blogspot.com) in /in/rFklb on line 4 Catchable fatal error: Argument 1 to finfo::buffer() must be of type ?string, bool given in /in/rFklb on line 4
Process exited with code 255.
Output for 5.0.0 - 5.2.17
Fatal error: Class 'finfo' not found in /in/rFklb on line 3
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: finfo in /in/rFklb on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: finfo in /in/rFklb on line 3