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
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Display Modes
Old 09-06-2008, 04:35 PM   #1 (permalink)
The Contributor
 
Join Date: May 2008
Location: Iran
Posts: 53
Thanks: 29
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.
__________________
http://www.ypy.ir/
Send a message via Yahoo to Yoosha
Yoosha is offline  
Reply With Quote
Old 09-06-2008, 05:57 PM   #2 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 354
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, 11:27 AM   #3 (permalink)
The Contributor
 
Join Date: May 2008
Location: Iran
Posts: 53
Thanks: 29
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));
__________________
http://www.ypy.ir/
Send a message via Yahoo to Yoosha
Yoosha is offline  
Reply With Quote
Old 09-12-2008, 06:53 PM   #4 (permalink)
The Contributor
 
Join Date: May 2008
Location: Iran
Posts: 53
Thanks: 29
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.
__________________
http://www.ypy.ir/
Send a message via Yahoo to Yoosha
Yoosha is offline  
Reply With Quote
Old 09-12-2008, 07:49 PM   #5 (permalink)
The Frequenter
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 354
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, 06:25 AM   #6 (permalink)
The Contributor
 
Join Date: May 2008
Location: Iran
Posts: 53
Thanks: 29
Yoosha is on a distinguished road
Application Go

Quote:
Originally Posted by xenon View Post
PHP Code:
echo strlen((string) 293898239382); 
WOW :)))))))))))
__________________
http://www.ypy.ir/
Send a message via Yahoo to Yoosha
Yoosha is offline  
Reply With Quote
Old 09-14-2008, 12:44 AM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 701
Thanks: 2
Salathe is on a distinguished road
Default

Try: echo strlen((string) 12345678901234567890);
__________________
Salathe is offline  
Reply With Quote
Old 09-14-2008, 02:04 PM   #8 (permalink)
The Addict
Zend Certified 
 
Join Date: Sep 2007
Location: Denmark
Posts: 241
Thanks: 5
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
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:11 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0