RE: [PHP] Is "gd" present?
| From: | Ford, Mike [LSS] | Date: | Thu, 05 Jun 2003 11:57:27 +0000 |
| Subject: | RE: [PHP] Is "gd" present? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-150329@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Esteban Fernandez [mailto:efernandez@tecsol.cl]
> Sent: 04 June 2003 16:09
>
> Also works... :)
>
> <?php
> $array = get_loaded_extensions();
> for ($i=0;$i<=count($array);$i++) {
> if ("gd" == $array[$i]) $installed = true;
> else $installed = false;
> }
This will only work if the "gd" entry is last in the array, as you don't exit the
loop after setting $installed to true. Plus a foreach loop would be better; and initialising before
the loop would be more efficient, too:
$installed = false;
foreach ($array as $extn):
if ("gd" == $extn):
$installed = true;
break;
endif;
endforeach;
But, even better, why not just use in_array():
$installed = in_array("gd", $array);
> if ($installed = true) echo "yeah... GD installed";
Arrgh! Firstly, this will assign true to $installed, then decide that's true (!) and echo
"yeah" -- you should have used == not =. Secondly, there is *never* any need to use the
comparison "== true" -- again that's just forcing PHP to do unnecessary work (since
the thing you're comparing to true must evaluate to true for the comparison to succeed and
return true, you can omit the comparison and just use the raw value in the test).
> else echo "shit.. GD not installed.";
> ?>
if ($installed) echo "yeah";
else echo "nope";
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211