You are here: Re: Is there a PHP command to « PHP Programming Language « IT news, forums, messages
Re: Is there a PHP command to

Posted by Rik Wasmus on 01/08/08 11:21

On Tue, 08 Jan 2008 12:01:51 +0100, <jools@by.com> wrote:

> In article <op.t4kpci035bnjuv@metallium.lan>, luiheidsgoeroe@hotmail.c=
om
> says...
>> On Mon, 07 Jan 2008 19:48:09 +0100, <jools@by.com> wrote:
>>
>> >
>> > Just wondering what the simplest way to sort IP addresses would be
>> > Is there a good way to sort that keeps them in sequence
>> > asort() sorts on the first character so that doesnt quite do it of =
=

>> course
>>
>> Convert them to a number (using usort())?
>> http://nl2.php.net/manual/en/function.ip2long.php
>> http://nl2.php.net/manual/en/function.long2ip.php
>> --
>> Rik Wasmus
>>
>
> Aha - I knew there had to be something that helped - thanks Rik.

Hmm, come to think of it...
Allthough not intended for this use, version_compare() would do the tric=
k =

without any problems I think. As the behavious of version_compare is =

clearly defined, and suited for (proven to be valid) IP-addresses, I'd g=
o =

with that:
<?php
$array =3D array(
'122.23.45.53',
'12.23.46.53',
'12.23.45.54',
'12.23.45.53',
'12.23.'
'12.23.45.53');
usort($array,'version_compare');
print_r($array);
?>

... unless you also need the insurance the IP adress is valid/stuff like =
=

256 is captured/converted, in which case ip2long is still better.
-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация