TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-06-2008, 03:35 PM   #1 (permalink)
The Contributor
 
Join Date: May 2008
Location: Iran
Posts: 53
Thanks: 33
Yoosha is on a distinguished road
Help How to count Integer lenght

Hi,
How can i count an Integer lenght?
Example: $X= 8766435322364576;

Also dif. between strval($X) V.S. (string)($X)?
Regards.
Send a message via Yahoo to Yoosha
Yoosha is offline  
Reply With Quote
Old 09-06-2008, 04:57 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

You can use strlen.

The only difference is speed there. (string) is an explicit cast (aka a language construct), whereas strval is a function, and therefore, is more memory consuming.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
Yoosha (09-12-2008)
Old 09-07-2008, 10:27 AM   #3 (permalink)
The Contributor
 
Join Date: May 2008
Location: Iran
Posts: 53
Thanks: 33
Yoosha is on a distinguished road
Default

Xenon: You can use strlen.

No i can't use that. This is for String, not Integer.
StringLength no IntegerLength!
Test this:

$X= 8766435322364545664565464654676;
echo(strlen($X));
Send a message via Yahoo to Yoosha
Yoosha is offline  
Reply With Quote
Old 09-12-2008, 05:53 PM   #4 (permalink)
The Contributor
 
Join Date: May 2008
Location: Iran
Posts: 53
Thanks: 33
Yoosha is on a distinguished road
Default

I found.
Finded:

function _Number_Length($Int_Input)
{
$_Int_Output= number_format($Int_Input, 0, '.', '');
return((integer)strlen($_Int_Output));
}

Resolved.
Send a message via Yahoo to Yoosha
Yoosha is offline  
Reply With Quote
Old 09-12-2008, 06:49 PM   #5 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Ok then, just convert the int to a string before passing it to strlen. Aka:

PHP Code:
echo strlen((string) 293898239382); 
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
Yoosha (09-13-2008)
Old 09-13-2008, 05:25 AM   #6 (permalink)
The Contributor
 
Join Date: May 2008
Location: Iran
Posts: 53
Thanks: 33
Yoosha is on a distinguished road
Application Go

Quote:
Originally Posted by xenon View Post
PHP Code:
echo strlen((string) 293898239382); 
WOW :)))))))))))
Send a message via Yahoo to Yoosha
Yoosha is offline  
Reply With Quote
Old 09-13-2008, 11:44 PM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Try: echo strlen((string) 12345678901234567890);
Salathe is offline  
Reply With Quote
Old 09-14-2008, 01:04 PM   #8 (permalink)
The Frequenter
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
Kalle is on a distinguished road
Default

Quote:
Originally Posted by Yoosha View Post
Xenon: You can use strlen.

No i can't use that. This is for String, not Integer.
StringLength no IntegerLength!
Test this:

$X= 8766435322364545664565464654676;
echo(strlen($X));
Its because the number is higher than PHP_INT_MAX, you need to cast it to a string like the others said before it will work :)
__________________
Send a message via MSN to Kalle Send a message via Skype™ to Kalle
Kalle is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:34 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design