Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hi Dreamweaver says there is a syntax error on the following line. Is it right?
if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))
Indexing the return value of a function is not supported in the version of PHP in use. Upgrade to a newer version, or turn it into separate statements.
It is probably not parsing for php 5.4 which is what is required to understand the function()[0] syntax.
Also your parameted for in_array() are incorrect
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
Dreamweaver is the CULPRIT !
Your code is just fine. I tried your code and it works fine.
Since you haven't disclosed us the variables. $file and $allowedExtensions. I assume this is what you must be doing.
Also, the if loop is just fine.
Get a new editor like PHPStorm or Eclipse for PHP
<?php
$file=array('name'=>'test.gif');
$allowedExtensions=array('.gif','.jpg','.png');
if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))
{
echo "Valid File Extension";
}
else
{
echo "Invalid File Extension";
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Hey there i have this snippet:
$profile_pic = imagecreatefromjpeg("upload_Main/".$user[1].".jpg");
This function works (upload_Main: folder:777 ; files:644)
But this snippet:
$profile_pic = imagecreatefromjpeg("upload_Sub/".$user[1].".jpg");
Doesnt work (upload_Sub: folder:777 ; files:644).
They have exactly the same files and the same right´s, so why does the second one not work? Any idea´s? thanks and greetings!
imagecreatefromjpeg():
Returns an image resource identifier on success, FALSE on errors.
I had it return False on an image that was manually re-named to a JPG, when it was actually a PNG.
I got an error saying:
'not a valid JPEG file'
You should look to see what error you get when performing that function, That way you'll know exactly what's goind bad.
One way to check for the error is creating a PHP file next to the image with:
<?php
echo imagecreatefromjpeg("path/to/image");
?>
run it in using 'php filename.php'
and looking in the console for the result
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Sorry for another noob question, but... Can someone please explain to me what the function myfunction is actually doing. I understand it's checking if the variables $a and $b are identical and than it's suppose to return 0 if they're identical but the next return is confusing. I see their using the ternary operators.
function myfunction($a,$b)
{
if ($a===$b)
{
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","b"=>"green","d"=>"blue");
$a3=array("e"=>"yellow","a"=>"red","d"=>"blue");
$result=array_diff_uassoc($a1,$a2,$a3,"myfunction");
print_r($result);
the print_r returns
Array ( [c] => blue )
but how did we get here...
As stated in the documentation of array_diff_uassoc, it returns the entries from first argument that are unique compared to other arguments. And the last argument is the name of the function it uses to check whether item is unique or not.
So because only $a1 contains 'c'=>'blue' it is returned.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$nopa = "Shotgun";
$weapon1 = array("Ingen","Shotgun","Glock 17","Revolver","AK 47","Barrett M82");
How can i do so this code will output a yes if the $weapon is equal to $nopa, else it would output a no. Any ideas?
you can use in_array from PHP documentation stated here: http://php.net/manual/en/function.in-array.php
Check the PHP function "in_array"
http://php.net/manual/en/function.in-array.php
if ( in_array($stringVar, $arrayVar) ) {
//do something
}
Careful about case, however.
If needle is a string, the comparison is done in a case-sensitive
manner.
check out the built-in in_array function:
http://php.net/manual/en/function.in-array.php
this is what You want:
<?
$nopa = "Shotgun";
$weapon1 = array("Ingen","Shotgun","Glock 17","Revolver","AK 47","Barrett M82");
if (in_array($nopa,$weapon1)){
echo 'YES';
} else {
echo 'NO';
}
?>
WORKING CODE
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm a newbie with PCRE in PHP. I'm trying to make a very basic shortcode function that could make something with a format like this one: {somealphanumericthing}
In essence I need a preg_match_all() that could find in my post these type of occurrences. I tried something like this:
$shortcode = preg_match_all('/^\b\{[a-zA-Z0-9_]+(\}\b)$/', $body, $found);
var_dump($shortcode);
if($shortcode==1) {
for($i=0;$i<count($found);$i++) {
print_r($found);
//do something nice
}
}
But unfortunately it's not working: I get int 0 to the test string {test}
A few things about the regular expression:
You don't need your line anchors since you are searching in a larger string.
There's not need to capture the closing }
Optimization, use the character class \w
Condensed:
/\b\{[a-zA-Z0-9_]+\}\b/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
The simple program is not returning the string,Please help.
<?php
function returnStr() {
return "fooBar";
}
$str=returnStr();
echo $str;
}
?>
It's a parse error:
$str=returnStr();
echo $str;
} // WHAT IS THIS BRACKET DOING HERE?
There's a fatal error tokenizing the code due the trailing/unmatched '}' remove that and the code will work. Then spend some time thinking about why you didn't know this already
There's an error in your code. The last } is useless.