Re: Getting totals
| From: | Richard Lynch | Date: | Wed, 07 Jun 2006 00:35:21 +0000 |
| Subject: | Re: Getting totals | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237518@lists.php.net to get a copy of this message | ||
On Tue, June 6, 2006 12:15 pm, Rob W. wrote:
> Ok, Here is my next problem.
>
> Inside my database, I have a list of ip's of about 10 blocks
Some databases, such as PostgreSQL, have native data format of IP and
functions to deal with them...
I don't suppose you are using one of those? :-)
> 192.168.100.0 all the way though 255
> along with
> 192.168.101.0 though 255
> and
> 192.168.102.0 though 255
> and soforth
>
> My problem is, is i'm trying to figure out a pattern to match so I can
> count how many ip's are in each block and display them.
Your Regex should probably be pretty simple...
Something like:
([[::digit::]])\.([[::digit::]])\.([[::digit::]])\.([[::digit::]])
Though god only knows what your db needs to grok that, or if it even
CAN do that...
> So far what I have gotten is a stristr match but it's not working
> correctly. I have a variable that basically weed's out the last digits
> of the ip it's self from help previously
>
> So my code so far is:
Oh.
Well if you want to do this in PHP in a loop, instead of in the DB
like it should be done, check out http://php.net/preg_match
and find
an example of IP quads in there somewhere.
> if (stristr($block,$address)) {
> $count_ip++;
> }
>
> $block would == 192.168.100
> $address would == 192.168.100.0 - 255
>
> Any help would be appricated.
--
Like Music?
http://l-i-e.com/artists.htm