Just like that, the parentheses at the beginning and at the end do nothing!
$extensao = ( end ( explode ('.', $_FILES [ "img" ][ "name"] ) ) ) ;
-----------^ ^----
The small problem of this code is that from php5.3 it generates a Strict Standards which is basically a Warning, the message is as follows:
Strict Standards: Only variables should be passed by Ference in
Now yes speaking of the parentheses that make the difference, to get the return(value) of explode()
to become a family member:
$extensao = end ( ( explode ('.', $_FILES [ "img" ][ "name"] ) ) ) ;
-------------------^ ^----
Take the test by displaying all the errors 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 will be generated a Warning or treat warnings or these types of gambiarras, in which case it is only create an additional varietal and pass to the function.
Parentheses Around Function Parameters no longer affect behaviour
How to Grab a File Extension
The most correct way to get the extension is to use pathinfo()
as shown that answer.
*Obs tried to do an example in ideone, phpfidle and 3v4l.org, it seems that directive that enables all errors is offline.
Okay, thannks....
– Josimara
+1 for
pathinfo
. To make the bullshit object-oriented I would do$file = new SplFileObject($_FILES [ "img" ][ "name"]);
– Wallace Maxters
@Wallacemaxters, I do not know this, I will look later. It is not pq solves that you should solve the problem thinking that everything is text/string manipulation. Thanks for the tip :D
– rray