Exactly like this, the parentheses at the beginning and at the end do nothing!
$extensao = ( end ( explode ('.', $_FILES [ "img" ][ "name"] ) ) ) ;
-----------^ ^----
The small problem with this code is that from php5.3 it generates a Strict Standards that basically is a warning, the message is as follows:
Strict Standards: Only variables should be passed by reference in
Now, speaking of the parentheses that make the difference, to force the return (value) of explode()
to make a reference add the parentheses:
$extensao = end ( ( explode ('.', $_FILES [ "img" ][ "name"] ) ) ) ;
-------------------^ ^----
Take the test by displaying all errors in this way:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
$extensao = end( (explode ('.', 'arquivo.ext' ) ) );
$extensao = end(explode ('.', 'arquivo.ext' )) ;
Update PHP7
Now in PHP7, even with these additional parentheses a warning will be generated, ie treat warnings or these types of gambiarras, in this case it is only necessary to create an additional variable and move to the function.
Parentheses around function parameters no longer affect behavior
How to grab the extension of a file
The most correct way to get the extension is to use pathinfo()
as shown this answer .
* I tried to make an example in ideone, phpfidle and 3v4l.org, it seems that directive that enables all errors is turned off.