Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 28
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
Po wysłaniu do Dariusza problemu jeszcze nie opisanego w poradach, odpowiedź pojawia się na stronach już po 24 godzinach. To jedna z najważniejszych zalet serwisu! Za około 100 złotych rocznie mam profesjonalnego i doświadczonego konsultanta od technologii internetowych! Polecam serwis z poradami każdemu webmasterowi, niezależnie od stażu pracy i umiejętności.

Paweł Kowalski
grupa hiperMEDIA.pl

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

phpversion

(PHP 3, PHP 4, PHP 5)

phpversion -- Gets the current PHP version

Description

string phpversion ( [string extension] )

Returns a string containing the version of the currently running PHP parser. If the optional extension parameter is specified, phpversion() returns the version of that extension, or FALSE if there is no version information associated or the extension isn't enabled.

Notatka: This information is also available in the predefined constant PHP_VERSION.

Przykład 1. phpversion() example

<?php
// prints e.g. 'Current PHP version: 4.1.1'
echo 'Current PHP version: ' . phpversion();

// prints e.g. '2.0' or nothing if the extension isn't enabled
echo phpversion('tidy');
?>

See also version_compare(), phpinfo(), phpcredits(), php_logo_guid(), and zend_version().




User Contributed Notes

25-Oct-2005 07:08

The version 4.3.10-16 does not "respect" the requiement for the above code. Use this fuction.

sample call:
if(!check_version(PHP_VERSION, "4.1.0") )
{
   echo 'Current PHP version: ' . PHP_VERSION . ' is too low for this code!<p>';
}

Function:
# Compares versions of software
# versions must must use the format ' x.y.z... '
# where (x, y, z) are numbers in [0-9]

function check_version($currentversion, $requiredversion)
{
   list($majorC, $minorC, $editC) = split('[/.-]', $currentversion);
   list($majorR, $minorR, $editR) = split('[/.-]', $requiredversion);
  
   if ($majorC > $majorR) return true;
   if ($majorC < $majorR) return false;
   // same major - check ninor
   if ($minorC > $minorR) return true;
   if ($minorC < $minorR) return false;
   // and same minor
   if ($editC  >= $editR)  return true;
   return true;
}


Willem
10-Oct-2005 01:02

A little more easier and compact ;)

<?
/**
 * bool phpversion2 ( string version )
 *
 * var version : user version of php needed to be compared to the server version of php,
 *                  must respect the correct format ' x.y.z ' where (x, y, z) are numbers in [0-9]
 */
 
function phpversion2 ($version = "5.0.5")
{
  
// does the ' user php version ' have the right format ?
  
if (preg_match("/(^\d+\.\d+\.\d+$)/", $version) == null)
   {
       return
false;
   }
  
   if (
str_replace(".", "", phpversion()) >= str_replace(".", "", $version))
   {
       return
true;
   }
  
   return
false;
}
?>


nick at divbyzero dot com
28-Jul-2005 10:06

Of course, if you want to COMPARE versions, you can't just compare them numerically, so try something like:

<?php
echo phpversion()."\n"; //4.3.10-15
$v2 = preg_replace("/[^0-9\.]+/","",phpversion()); //4.3.1015
$v=$v2-0; // 4.3
$v2=substr($v2,strlen($v."")+1); //1015
echo $v." ".$v2."\n";

echo (
$v>4.3 || ($v==4.3 && $v2>=1))."\n"; // 1 if >= 4.3.1
?>


ground-pilot at net-pilots.com
22-Jan-2005 08:52

Difference from bleeding edge server and production server where I couldn't use the phpversion() function. Came up with this to grab it from the command line instead. Note that the 'command line' version result , and 'http server api' version result could be two or more different versions, and not matching each other. So this may return a misleading value for your environment? Be careful if you have updated the web server api and not the command line, or visa-versa. ;)

But for me - it works.

<?php
$PHP_VERSION
= get_my_phpver();

echo
"PHP_VERSION = $PHP_VERSION<br>";

function
get_my_phpver() {
// USE :
//  $PHP_VERSION = get_my_phpver();
// CAVEAT NOTES :   
//  exec() will only return last line
//  passthru() will always show output, even when you ob_start() the output.
//  shell_exec() will return ALL lines of output but not forced
  
$my_phpver = trim(substr(shell_exec('php -v'), 3, 6));
  
// returns "4.3.1" of "PHP 4.3.1 (cgi)..." and removes white spaces
  
return $my_phpver;
}
?>

Of course this would also do the trick...

<?php
$PHP_VERSION
= trim(substr(shell_exec('php -v'), 3, 6));
echo
"PHP_VERSION = $PHP_VERSION<br>";
?>

And as always, there are OTHER method, but this works for me.

Hope this helps someone else out as well. :)


 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt