Page 1 of 1

[SOLVED]Warning: Division by zero

Posted: Sun Jan 14, 2007 3:28 pm
by JellyFish
It's been a while sense I've been on php code forum. Been working on client stuff.

I get a php error:
Warning: Division by zero in "the url" on line 286
line 286:

Code: Select all

$newwidth = ($newwidth/$imgheight);
line 284 to 286:

Code: Select all

list($imgwidth, $imghieght) = getimagesize("Url");
$newwidth = (($imgwidth * 100));
$newwidth = ($newwidth/$imgheight);
I don't understand why the php parser is saying that ($newwidth/$imgheight) is division by 0??? It's clearly not zero at all.

According to my arithmetics it would work perfect. Unless I'm going wrong somewhere.

Posted: Sun Jan 14, 2007 3:52 pm
by Kieran Huggins
http://www.php.net/manual/en/function.list.php

List assigns variables backwards, that is, from right to left.

getimagesize() returns an array of 4 elements. Since you're only collecting two, you're collecting the right-most two (type & attr).

This should work:

Code: Select all

list($imgwidth, $imgheight, $imgtype, $imgattr) = getimagesize("Url");
$newwidth = (($imgwidth * 100));
$newwidth = ($newwidth/$imgheight);

Posted: Sun Jan 14, 2007 3:55 pm
by decipher
and your spelling of $imgheight is different to variable you used in the list:
list($imgwidth, $imghieght) ;)

Posted: Sun Jan 14, 2007 4:01 pm
by JellyFish
Damn I feel stupid...

Posted: Sun Jan 14, 2007 4:11 pm
by decipher
trust the parser ;)

Posted: Sun Jan 14, 2007 4:32 pm
by JellyFish
Thanks guys. Post out.