MyBB Community Forums

Full Version: 1000 Post + Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
If using this in a plugin im creating , but if the post number exceeds 1000 it wont display what i intend it to display

if ($post['postnum'] > intval($mybb->settings['my_setting']))
    {    etc.........

Is the comma in the number the problem ? Im assuming it is.

"1,000"
intval("1,000") returns 1.
So for example, if i wanted to display an image for a user that had a post count of 1,010 posts or higher , what do you suggest ?

Bear in mind that this figure can vary from whatever the admin decides to input in ACP.
Its actually pretty easy to fix this Wink
$postnum = $post['postnum'];
$newpostnum = '';
for( $i = 0; $i < strlen($postnum); $i++ )
{
     if(is_numeric($postnum[$i]))
     {
          $newpostnum .= $postnum[$i];
     }
}
$postnum = intval($newpostnum);
Just don't type the comma in 'my_setting': 1000. It's never a good idea to store numbers with a group symbol.
(2010-12-17, 08:01 PM)querschlaeger Wrote: [ -> ]Just don't type the comma in 'my_setting': 1000. It's never a good idea to store numbers with a group symbol.

Or that. For some reason I thought Janota was saying that $post['postnum'] was doing it.
Thats how i am currently entering the number in 'my_setting' 1000
(2010-12-17, 08:04 PM)Janota Wrote: [ -> ]Ok thanks Dylan , I'll try that.

@querschlaeger

Thats how i am currently entering the number in 'my_setting' 1000

So perhaps $post['postnum'] is stored with commas? I'm not sure without looking. Let us know.
$post['postnum'] is the users current postcount, but when the user exceeds 1000 , it displays their post count like so : 1,000
(2010-12-17, 07:44 PM)Dylan M. Wrote: [ -> ]intval("1,000") returns 1.

That should actually return 1000. 1.000 would return 1 Toungue
At least, if I remember right, that's how PHP is setup by default - not sure if there's a setting to change it.
Pages: 1 2 3