cvs: phpdoc /en/reference/info/functions version-compare.xml
| From: | Philip Olson | Date: | Wed, 21 May 2008 06:39:44 +0000 |
| Subject: | cvs: phpdoc /en/reference/info/functions version-compare.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-1666@lists.php.net to get a copy of this message | ||
philip Wed May 21 06:39:44 2008 UTC
Modified files:
/phpdoc/en/reference/info/functions version-compare.xml
Log:
Rewrote and added examples, added new information, see also, and added markup
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/info/functions/version-compare.xml?r1=1.13&r2=1.14&diff_format=u
Index: phpdoc/en/reference/info/functions/version-compare.xml
diff -u phpdoc/en/reference/info/functions/version-compare.xml:1.13
phpdoc/en/reference/info/functions/version-compare.xml:1.14
--- phpdoc/en/reference/info/functions/version-compare.xml:1.13 Wed Jun 20 22:24:48 2007
+++ phpdoc/en/reference/info/functions/version-compare.xml Wed May 21 06:39:44 2008
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.13 $ -->
+<!-- $Revision: 1.14 $ -->
<refentry xml:id="function.version-compare" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>version_compare</refname>
@@ -69,9 +69,10 @@
<literal>ge</literal>, <literal>==</literal>,
<literal>=</literal>, <literal>eq</literal>,
<literal>!=</literal>, <literal><></literal>,
- <literal>ne</literal> respectively. Using this argument, the
- function will return &true; if the relationship is the one specified
- by the operator, &false; otherwise.
+ <literal>ne</literal> respectively.
+ </para>
+ <para>
+ This parameter is case-sensitive, so values should be lowercase.
</para>
</listitem>
</varlistentry>
@@ -82,26 +83,46 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
- <function>version_compare</function> returns -1 if the first
- version is lower than the second, 0 if they are equal, and +1 if
- the second is lower.
+ By default, <function>version_compare</function> returns
+ <literal>-1</literal> if the first version is lower than the second,
+ <literal>0</literal> if they are equal, and
+ <literal>1</literal> if the second is lower.
+ </para>
+ <para>
+ When using the optional <parameter>operator</parameter> argument, the
+ function will return &true; if the relationship is the one specified
+ by the operator, &false; otherwise.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
+ The examples below use the <constant>PHP_VERSION</constant> constant,
+ because it contains the value of the PHP version that is executing
+ the code.
+ </para>
+ <para>
<example>
- <title><function>version_compare</function> example</title>
+ <title><function>version_compare</function> examples</title>
<programlisting role="php">
<![CDATA[
<?php
-// prints -1
-echo version_compare("4.0.4", "4.0.6");
-
-// these all print 1
-echo version_compare("4.0.4", "4.0.6", "<");
-echo version_compare("4.0.6", "4.0.6", "eq");
+if (version_compare(PHP_VERSION, '6.0.0') === 1) {
+ echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . "\n";
+}
+
+if (version_compare(PHP_VERSION, '5.3.0') === 1) {
+ echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
+}
+
+if (version_compare(PHP_VERSION, '5.0.0', '>')) {
+ echo 'I am using PHP 5, my version: ' . PHP_VERSION . "\n";
+}
+
+if (version_compare(PHP_VERSION, '5.0.0', '<')) {
+ echo 'I am using PHP 4, my version: ' . PHP_VERSION . "\n";
+}
?>
]]>
</programlisting>
@@ -116,6 +137,23 @@
The <constant>PHP_VERSION</constant> constant holds current PHP version.
</para>
</note>
+ <note>
+ <para>
+ Note that pre-release versions, such as 5.3.0-dev, are considered
+ lower than their final release counterparts (like 5.3.0).
+ </para>
+ </note>
+ </refsect1>
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
+ <para>
+ <simplelist>
+ <member><function>phpversion</function></member>
+ <member><function>php_uname</function></member>
+ <member><function>function_exists</function></member>
+ </simplelist>
+ </para>
</refsect1>
</refentry>