Re: [PHP] Integer

2013-02-01 Thread tamouse mailing lists
On Fri, Feb 1, 2013 at 11:27 PM, tamouse mailing lists
 wrote:
> On Fri, Feb 1, 2013 at 10:40 PM, Ron Piggott
>  wrote:
>> In the following the “2.” means a moderator response and “25” is the account 
>> # of the moderator.
>>
>> >
>> $author = 2.00025
>>
>> ?>
>>
>> How can I get the 25 by itself?
>> - I want to drop the “2.” and remove all the zero’s
>>
>> Would it be best to turn this into a STRING?

Sorry for complicating things. I didn't read your request carefully enough.

YES, treat it as a string, and if you just need the last 2 digits,
just grab the substring:

php > $author = substr('2.00025',-2);
php > echo $author;
25

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Integer

2013-02-01 Thread Adam Richardson
On Fri, Feb 1, 2013 at 11:40 PM, Ron Piggott  wrote:

> How can I get the 25 by itself?
> - I want to drop the “2.” and remove all the zero’s
>
> Would it be best to turn this into a STRING?
>

I would recommend turning it into a string, splitting the string at the
decimal, then scanning the second string for the first non-zero and storing
the subsequent characters. Working with floats at that precision level
would likely lead to tragic results:

"10.0 times .1 is hardly ever 1.0"
http://www.eg.bucknell.edu/~xmeng/Course/CS2330/Handout/StyleKP.html

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Integer

2013-02-01 Thread tamouse mailing lists
On Fri, Feb 1, 2013 at 10:40 PM, Ron Piggott
 wrote:
> In the following the “2.” means a moderator response and “25” is the account 
> # of the moderator.
>
> 
> $author = 2.00025
>
> ?>
>
> How can I get the 25 by itself?
> - I want to drop the “2.” and remove all the zero’s
>
> Would it be best to turn this into a STRING?
>
> Any suggestions?

Storing data as a float is a bad idea. Way bad. Also, I think that's
too many significant digits for php to handle in a float.

You should store data in an accessible way. For instance, assuming
there are actually only two pieces of interesting data there, you
could store them as a hash:

php > $author = Array('account' => 25, 'response' => 2);
php > var_dump($author);
array(2) {
  ["account"]=>
  int(25)
  ["response"]=>
  int(2)
}

If that data is coming from somewhere beyond your control and is
presented as that, then parsing as a string will be the way to go.
Again, assuming there is no other useful information, a simple regexp
to parse it would be:

php > if (preg_match('/(\d+)\.0+(\d+)/','2.00025',$matches))
{
php {   $author = Array('account' => $matches[2], 'response' => $matches[1]);
php { }
php > // else handle error if need be
php > var_dump($author);
array(2) {
  ["account"]=>
  string(2) "25"
  ["response"]=>
  string(1) "2"
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Integer

2013-02-01 Thread Ron Piggott
In the following the “2.” means a moderator response and “25” is the account # 
of the moderator.   



How can I get the 25 by itself?  
- I want to drop the “2.” and remove all the zero’s

Would it be best to turn this into a STRING?

Any suggestions?


Ron Piggott



www.TheVerseOfTheDay.info 


RE: [PHP] how to calculate how much data does each ip address use ?

2013-02-01 Thread Mike Mackintosh


 Original message 
From: Sean Greenslade  
Date:  
To: Bulent Malik  
Cc: php-general@lists.php.net 
Subject: RE: [PHP] how to calculate how much data does each ip address use ? 
 
On Feb 1, 2013 10:25 AM, "Bulent Malik"  wrote:
>
>
>
> >This task is not really suited for php. I would suggest looking into
Ntop.
> >It does exactly what you described.
>
> >> Hello
> >>
> >> I have  a freebsdbox firewall . also I have some internet customers.
> >> I want to save how much data they used in a table ( such as mysql
> >> table ) for each ip address.
> >>Apache2, php5 and mysql5.5 work on the box.
> >>
> >> How can I do it ?  any script or tool.
> >>
> >> Thanks
>
> How can i save in table using ntop ?  is there any document ?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


Look at www.highonphp.com/regex-pattern-parsing-ifconfig

You can use exec to run ifconfig and parse the output using the above.

RE: [PHP] how to calculate how much data does each ip address use ?

2013-02-01 Thread Sean Greenslade
On Feb 1, 2013 10:25 AM, "Bulent Malik"  wrote:
>
>
>
> >This task is not really suited for php. I would suggest looking into
Ntop.
> >It does exactly what you described.
>
> >> Hello
> >>
> >> I have  a freebsdbox firewall . also I have some internet customers.
> >> I want to save how much data they used in a table ( such as mysql
> >> table ) for each ip address.
> >>Apache2, php5 and mysql5.5 work on the box.
> >>
> >> How can I do it ?  any script or tool.
> >>
> >> Thanks
>
> How can i save in table using ntop ?  is there any document ?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Read the man pages. There are sql export options that you can specify on
run.


RE: [PHP] how to calculate how much data does each ip address use ?

2013-02-01 Thread Bulent Malik


>This task is not really suited for php. I would suggest looking into Ntop.
>It does exactly what you described.

>> Hello
>>
>> I have  a freebsdbox firewall . also I have some internet customers.  
>> I want to save how much data they used in a table ( such as mysql 
>> table ) for each ip address.
>>Apache2, php5 and mysql5.5 work on the box.
>>
>> How can I do it ?  any script or tool.
>>
>> Thanks

How can i save in table using ntop ?  is there any document ? 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Complex MySQL query for lowest price

2013-02-01 Thread Angela Barone
Thank you for everyone's input.  Someone suggested the MySQL list, so I 
posted my question there and got the answer I needed.

Regards,
Angela
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to calculate how much data does each ip address use ?

2013-02-01 Thread Sean Greenslade
This task is not really suited for php. I would suggest looking into Ntop.
It does exactly what you described.
On Feb 1, 2013 9:40 AM, "Bulent Malik"  wrote:

> Hello
>
> I have  a freebsdbox firewall . also I have some internet customers.  I
> want
> to save how much data they used in a table ( such as mysql table ) for each
> ip address.
> Apache2, php5 and mysql5.5 work on the box.
>
> How can I do it ?  any script or tool.
>
> Thanks
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


[PHP] how to calculate how much data does each ip address use ?

2013-02-01 Thread Bulent Malik
Hello

I have  a freebsdbox firewall . also I have some internet customers.  I want
to save how much data they used in a table ( such as mysql table ) for each
ip address.
Apache2, php5 and mysql5.5 work on the box.

How can I do it ?  any script or tool.

Thanks


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php