473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

PHP Version Number Comparison issue

I have written several applications that have very specific
functionality that is version-dependent, furthermore, requirements
dictate my apps span multiple versions of PHP.

I have written a function that detects which version of PHP and
ultimately converts it into integer form, however, I am foreseeing a
problem in doing this which I will illustrate to you now:

[PHP]
if (!function_exists('get_php_version_int')) {
/**
* Get PHP version into integer form
*
* @access public
* @return int $phpVersionInt
*/
function get_php_version_int($seedVersion = '') {
$phpVersion = (strlen($seedVersion) > 0) ? str_replace('.', '',
$seedVersion) : str_replace('.', '', phpversion());
return (int)(preg_replace('/^([0-9]+).*$/','$1', $phpVersion));
}
}
echo '5.0.4 > 4.3.11? '. ('5.0.4' > '4.3.11') . ' BUT.. using
get_php_version_int? ' . (get_php_version_int('5.0.4') >
get_php_version_int('4.3.11')) .
'<P> 4.3.11 > 4.3.2? ' . ('4.3.11' > '4.3.2') . ' BUT.. using
get_php_version_int? ' . (get_php_version_int('4.3.11') >
get_php_version_int('4.3.2')) .
'<P> 4.3.2 > 4.1.10? ' . ('4.3.2' > '4.1.10') . ' BUT.. using
get_php_version_int? ' . (get_php_version_int('4.3.2') >
get_php_version_int('4.1.10'));

[/PHP]

Produces the following results:

5.0.4 > 4.3.11? 1 BUT.. using get_php_version_int?

4.3.11 > 4.3.2? BUT.. using get_php_version_int? 1

4.3.2 > 4.1.10? 1 BUT.. using get_php_version_int?
The first line is correct if the versions are kept as strings but
incorrect if converted to integer. The second line is wrong if the
versions are kept as strings but correct if converted to integer. The
third line is correct if the versions are kept as strings but incorrect
if converted to integer.

My code throughout my apps depends on an integer format for now for
version number comparison using get_php_version_int(). What would you
recommend I do that might be better yet requires the least amount of
code changes?

Thanks
Phil

Dec 20 '05 #1
1 2275
Why not version_compare()?

Dec 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jordan T. Cox | last post by:
Hello everyone, I've googled through the older group messages - but I'm not quite sure what to use for search terms... so, if this has already been asked - I apologize. I'm wondering how...
8
by: Keith | last post by:
Is there a function for comparing version numbers? E.g. 0.1.0 < 0.1.2 1.876b < 1.876c 3.2.2 < 3.4 Keith
8
by: Frodio Jose Serrano | last post by:
Hello to anyone, We operateing one of the largest mainframe in our areas and we are using an old version of datapropagator for z/os. Our machines has reached the max DASD and cannot keep up with...
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
1
by: Tom | last post by:
I have two version numbers - one for my application and another from a manifest, database, whatever - that isn't important. Now that I have these two version numbers (in the form...
5
by: B1ackwater | last post by:
We've fooled around with Access a bit, but only using the single-user store-bought version. It seems to be a good database - versatile and infinitely programmable - and can apparently be used as a...
0
by: ewingate | last post by:
I seem to be having an issue with version incrementation. When building my app, it will not consistently increment the version number. I currently have the attribute set at "1.2.*" and the default...
1
by: ewingate | last post by:
I cannot seem to get the version number of my VB app to increment properly in VS2005. When I build the app each day the "build" number increments with no problem as does the version number but if I...
10
by: akselo | last post by:
Hi folks, I am working on a routine that will select a sample of parcels from a table. Each parcel belongs to a census tract, and depending on which tract, a certain calculation is applied. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.