RE: [PHP] Is gd present?

2003-06-05 Thread Ford, Mike [LSS]
 -Original Message-
 From: Esteban Fernandez [mailto:[EMAIL PROTECTED]
 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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Is gd present?

2003-06-05 Thread Ford, Mike [LSS]
 -Original Message-
 From: Svein Larsen [mailto:[EMAIL PROTECTED]
 Sent: 04 June 2003 16:22
 
 $gd_loaded = (extension_loaded('gd'))?1:0;

Well, this also fails the simple-as-possible test: if the value returned by
extension_loaded() can be used to drive the ?: operator, it must be
evaluable as a Boolean; this means you can use it directly for later use in
an if() or similar context:

   $gd_loaded = extension_loaded('gd');

(And, indeed, a quick look at the manual reveals that extension_loaded
returns a bool, which is exactly what you want without any further ado.)

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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is gd present?

2003-06-05 Thread Svein Larsen
Thats true, but its more overhead calling a function than compare a variable.
Thats why i want to calll the function only once.

- Svein

On Thursday 05 June 2003 14:03, Ford, Mike [LSS] wrote:
  -Original Message-
  From: Svein Larsen [mailto:[EMAIL PROTECTED]
  Sent: 04 June 2003 16:22
 
  $gd_loaded = (extension_loaded('gd'))?1:0;

 Well, this also fails the simple-as-possible test: if the value returned by
 extension_loaded() can be used to drive the ?: operator, it must be
 evaluable as a Boolean; this means you can use it directly for later use in
 an if() or similar context:

$gd_loaded = extension_loaded('gd');

 (And, indeed, a quick look at the manual reveals that extension_loaded
 returns a bool, which is exactly what you want without any further ado.)

 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: [EMAIL PROTECTED]
 Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is gd present?

2003-06-05 Thread CPT John W. Holmes
   $gd_loaded = (extension_loaded('gd'))?1:0;
 
  Well, this also fails the simple-as-possible test: if the value returned
by
  extension_loaded() can be used to drive the ?: operator, it must be
  evaluable as a Boolean; this means you can use it directly for later use
in
  an if() or similar context:
 
 $gd_loaded = extension_loaded('gd');
 
  (And, indeed, a quick look at the manual reveals that extension_loaded
  returns a bool, which is exactly what you want without any further ado.)

 Thats true, but its more overhead calling a function than compare a
variable.
 Thats why i want to calll the function only once.

Umm... the function is only called once in both examples...

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Is gd present?

2003-06-05 Thread Todd Cary




Is there a way to check within an application if the "gd" library has been
installed?

Todd
-- 

 




Re: [PHP] Is gd present?

2003-06-05 Thread CPT John W. Holmes
 Is there a way to check within an application if the gd library has 
 been installed?

Maybe get_loaded_extensions() 

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is gd present?

2003-06-05 Thread Esteban Fernandez
Also works... :)

?php
$array = get_loaded_extensions();
for ($i=0;$i=count($array);$i++) {
if (gd == $array[$i])  $installed = true;
else $installed = false;
}
if ($installed = true) echo yeah... GD installed;
else echo shit.. GD not installed.;
?

Regards.
EF.


Cpt John W. Holmes [EMAIL PROTECTED] escribió en el mensaje
news:[EMAIL PROTECTED]
  Is there a way to check within an application if the gd library has
  been installed?

 Maybe get_loaded_extensions() 

 ---John Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is gd present?

2003-06-05 Thread Armand Turpel
This check if gd is installed and which version.

if( $img = @imageCreate(1, 1) )
{
 // Check if GD version = 2.0.1
 //
 $img = @imageCreateTrueColor(1, 1);
 if (!$img) 
 { 
 echo 'gd  2.0.1 installed';
 }
 else
 {
 echo 'gd = 2.0.1 installed';
 }
 }
 else
 {
echo 'No gd image tool available!';
 }  


- Original Message - 
From: CPT John W. Holmes [EMAIL PROTECTED]
To: Todd Cary [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Wednesday, June 04, 2003 4:11 PM
Subject: Re: [PHP] Is gd present?


  Is there a way to check within an application if the gd library has 
  been installed?
 
 Maybe get_loaded_extensions() 
 
 ---John Holmes...
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Is gd present?

2003-06-05 Thread Svein Larsen
$gd_loaded = (extension_loaded('gd'))?1:0;

Then you can use if ($gd_loaded) later in your code.

- Svein

 -Original Message-
 From: Esteban Fernandez [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, June 04, 2003 17:09
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Is gd present?
 
 
 Also works... :)
 
 ?php
 $array = get_loaded_extensions();
 for ($i=0;$i=count($array);$i++) {
 if (gd == $array[$i])  $installed = true;
 else $installed = false;
 }
 if ($installed = true) echo yeah... GD installed;
 else echo shit.. GD not installed.;
 ?
 
 Regards.
 EF.
 
 
 Cpt John W. Holmes [EMAIL PROTECTED] escribió en 
 el mensaje news:[EMAIL PROTECTED]
   Is there a way to check within an application if the gd library 
   has been installed?
 
  Maybe get_loaded_extensions() 
 
  ---John Holmes...
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Is gd present?

2003-06-05 Thread Esteban Fernandez
Everyday i learn some new :)

Svein Larsen [EMAIL PROTECTED] escribió en el mensaje
news:[EMAIL PROTECTED]
$gd_loaded = (extension_loaded('gd'))?1:0;

Then you can use if ($gd_loaded) later in your code.

- Svein

 -Original Message-
 From: Esteban Fernandez [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, June 04, 2003 17:09
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Is gd present?


 Also works... :)

 ?php
 $array = get_loaded_extensions();
 for ($i=0;$i=count($array);$i++) {
 if (gd == $array[$i])  $installed = true;
 else $installed = false;
 }
 if ($installed = true) echo yeah... GD installed;
 else echo shit.. GD not installed.;
 ?

 Regards.
 EF.


 Cpt John W. Holmes [EMAIL PROTECTED] escribió en
 el mensaje news:[EMAIL PROTECTED]
   Is there a way to check within an application if the gd library
   has been installed?
 
  Maybe get_loaded_extensions() 
 
  ---John Holmes...



 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php