Check this one out (I use it to define functions for versions of PHP that don't
have wordwrap defined for example):
  // Function to determine if the current version of PHP is
  // at least the one specified as a string in the parameter.
  // This is needed because string comparison isn't always accurate:
  // "4.0.2">"4.0.12" as strings, although that's not true when
  // speaking of comparing versions.

  // Usage example:
  // if (!isphpver("4.0.2"))
  // {
  //   [do something]
  // }

  // Bogdan Stancescu <[EMAIL PROTECTED]>, November 2001
  // You may freely use this function as long as you keep the header
  function isphpver($minver)
  {
    $itis=2; // That is, undecided
    $minimum=explode(".",$minver);
    $current=explode(".",phpversion());
    for ($i=0;(($i<sizeof($current)) && ($i<sizeof($minimum)));$i++)
    {
      if ($current[$i]>$minimum[$i])
      {
        $itis=true; // In this case, we have a winner
        break;
      }
      if ($current[$i]<$minimum[$i]) // >
      {
        $itis=false; // In this case, we have a loser
        break;
      }
    }
    if ($itis==2) // This would only happen if all the common version
                  // components are identical. But there are may be
                  // differences:
                  // Example 1: comparing "4.0.1" with "4.0" would be
                  //            identical for now, but the condition
                  //            is satisfied;
                  // Example 2: comparing "4.0" with "4.0.1" - identical
                  //            for now, but the condition is NOT
                  //            satisfied
    {
      if (sizeof($current)>=sizeof($minimum))
      {
        $itis=true;
      }
      else
      {
        // Ok, only one more chance: if for example the user
        // specified "4.0.0" and phpversion returned "4.0".
        for ($i=sizeof($current)-1;$i<sizeof($minimum);$i++) // >
        {
          if ($minimum[$i])
          {
            $itis=false;
          }
        }
        if ($itis==2)
        {
          $itis=true;
        }
      }
    }
    return($itis);
  }

Alan McFarlane wrote:

> What's the best method for checking the PHP version number.
>
> I'm assuming that include() was available in all versions, so, from my main
> index.php script, I include a local script (common.php) :
>
> <?php
> // assume minimum version of PHP required is 4.0.5
> if (phpversion() < 4) { die("wrong version"); }
> $ver = explode(".", phpversion());
> if ($ver[2] < 5) { die("wrong version"); }
> ?>
>
> The problem I can see is that some of the earlier 4+ versions had a funny
> number scheme - i.e. 4.0.1pl2.
>
> Does anyone have a complete list of version numbers (or a better method of
> version checking)?
>
> --
> 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

Reply via email to