Re: [PHP] problem with intval and !=
* Thus wrote Cesar Cordovez ([EMAIL PROTECTED]): Can somebody explain me why is this happening? $value = 12.3; $number = intval($value); echo Number: $number, Value: $valuebr; // echoes: Number: 12, Value: 12.3 I'm guessing you wondering why the .3 is removed. Thats because 12.3 isn't an integer but a float. $number = floatval($value); if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } The previous should be echoing Bad. (I think!) correct. If you use the floatval() it will echo Good. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
What versio of php? I get Bad (which is good ;) Cesar Cordovez wrote: Can somebody explain me why is this happening? $value = 12.3; $number = intval($value); echo Number: $number, Value: $valuebr; // echoes: Number: 12, Value: 12.3 if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } The previous should be echoing Bad. (I think!) Cesar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
Curt: My fault! You are right, but thats not what I want. $value comes from a form filled by a user. I want $value to be an integer. Not a float. So if the user types 12.3 the system has to send an error msg. Therefore the procedure. By-the-way, Im using PHP 4.3.3 (on windows XP profesional. Don't say a thing!!! I rather work on my mac!) =) Cesar Curt Zirzow wrote: * Thus wrote Cesar Cordovez ([EMAIL PROTECTED]): Can somebody explain me why is this happening? $value = 12.3; $number = intval($value); echo Number: $number, Value: $valuebr; // echoes: Number: 12, Value: 12.3 I'm guessing you wondering why the .3 is removed. Thats because 12.3 isn't an integer but a float. $number = floatval($value); if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } The previous should be echoing Bad. (I think!) correct. If you use the floatval() it will echo Good. Curt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
* Thus wrote Cesar Cordovez ([EMAIL PROTECTED]): Curt: My fault! You are right, but thats not what I want. $value comes from a form filled by a user. I want $value to be an integer. Not a float. So if the user types 12.3 the system has to send an error msg. Yeah, after reading merek's response I realized I missed what exactly your problem is. Therefore the procedure. By-the-way, Im using PHP 4.3.3 (on windows XP profesional. Don't say a thing!!! I rather work on my mac!) =) Thats odd, I come up with a 'Bad' echo also. The only thing I can think of is there is some sort of implicit casting happening to the $value within the comparison. But it does seem very strange that XP would cast but *nix doesn't In that case test the condition reversed: if ($value != $number) I'm at a loss as to why it doesn't work on your system. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
The other purpose of this procedure is if the user types 12asdasd into $value, $number will be assigned 12 so $value and $number are not the same, meaning $value is not a number. Which is correct, but the procedure is not working correctly in PHP when it should. (It works in c, c++, fortran and, believe it or not HyperCard!!!) Cesar. Cesar Cordovez wrote: Curt: My fault! You are right, but thats not what I want. $value comes from a form filled by a user. I want $value to be an integer. Not a float. So if the user types 12.3 the system has to send an error msg. Therefore the procedure. By-the-way, Im using PHP 4.3.3 (on windows XP profesional. Don't say a thing!!! I rather work on my mac!) =) Cesar Curt Zirzow wrote: * Thus wrote Cesar Cordovez ([EMAIL PROTECTED]): Can somebody explain me why is this happening? $value = 12.3; $number = intval($value); echo Number: $number, Value: $valuebr; // echoes: Number: 12, Value: 12.3 I'm guessing you wondering why the .3 is removed. Thats because 12.3 isn't an integer but a float. $number = floatval($value); if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } The previous should be echoing Bad. (I think!) correct. If you use the floatval() it will echo Good. Curt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
This is getting weird by the minute. I changed the script: if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } to: ($number != $value) ($number !== $value) ($number === $value) and I get the Good stuff... At this point, I think I have to change the procedure. This is not good. Any sugestions on how to now if the user types an integer number in a field? Cesar Curt Zirzow wrote: * Thus wrote Cesar Cordovez ([EMAIL PROTECTED]): Curt: My fault! You are right, but thats not what I want. $value comes from a form filled by a user. I want $value to be an integer. Not a float. So if the user types 12.3 the system has to send an error msg. Yeah, after reading merek's response I realized I missed what exactly your problem is. Therefore the procedure. By-the-way, Im using PHP 4.3.3 (on windows XP profesional. Don't say a thing!!! I rather work on my mac!) =) Thats odd, I come up with a 'Bad' echo also. The only thing I can think of is there is some sort of implicit casting happening to the $value within the comparison. But it does seem very strange that XP would cast but *nix doesn't In that case test the condition reversed: if ($value != $number) I'm at a loss as to why it doesn't work on your system. Curt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
why don't you use this?? http://it.php.net/manual/it/function.is-integer.php Cesar Cordovez ha scritto: This is getting weird by the minute. I changed the script: if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } to: ($number != $value) ($number !== $value) ($number === $value) and I get the Good stuff... At this point, I think I have to change the procedure. This is not good. Any sugestions on how to now if the user types an integer number in a field? Cesar Curt Zirzow wrote: * Thus wrote Cesar Cordovez ([EMAIL PROTECTED]): Curt: My fault! You are right, but thats not what I want. $value comes from a form filled by a user. I want $value to be an integer. Not a float. So if the user types 12.3 the system has to send an error msg. Yeah, after reading merek's response I realized I missed what exactly your problem is. Therefore the procedure. By-the-way, Im using PHP 4.3.3 (on windows XP profesional. Don't say a thing!!! I rather work on my mac!) =) Thats odd, I come up with a 'Bad' echo also. The only thing I can think of is there is some sort of implicit casting happening to the $value within the comparison. But it does seem very strange that XP would cast but *nix doesn't In that case test the condition reversed: if ($value != $number) I'm at a loss as to why it doesn't work on your system. Curt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
This should be reported as a bug. I tried few searches and I got Warning: mysql_fetch_array(): 9 is not a valid MySQL result resource in /local/Web/sites/php-bugs-web/search.php on line 182 on bugs.php.net Cesar Cordovez wrote: This is getting weird by the minute. I changed the script: if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } to: ($number != $value) ($number !== $value) ($number === $value) and I get the Good stuff... At this point, I think I have to change the procedure. This is not good. Any sugestions on how to now if the user types an integer number in a field? Cesar Curt Zirzow wrote: * Thus wrote Cesar Cordovez ([EMAIL PROTECTED]): Curt: My fault! You are right, but thats not what I want. $value comes from a form filled by a user. I want $value to be an integer. Not a float. So if the user types 12.3 the system has to send an error msg. Yeah, after reading merek's response I realized I missed what exactly your problem is. Therefore the procedure. By-the-way, Im using PHP 4.3.3 (on windows XP profesional. Don't say a thing!!! I rather work on my mac!) =) Thats odd, I come up with a 'Bad' echo also. The only thing I can think of is there is some sort of implicit casting happening to the $value within the comparison. But it does seem very strange that XP would cast but *nix doesn't In that case test the condition reversed: if ($value != $number) I'm at a loss as to why it doesn't work on your system. Curt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
Because is_integer(12thisisnotanumber) retuns true. Andrea Pinnisi wrote: why don't you use this?? http://it.php.net/manual/it/function.is-integer.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
On Thu, 2003-10-23 at 11:41, Cesar Cordovez wrote: Because is_integer(12thisisnotanumber) retuns true. Not for me it doesn't. Returns false. Prolly because it's a string. Even the following returns false for me: is_integer(12) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
On Thu, 2003-10-23 at 11:21, Cesar Cordovez wrote: At this point, I think I have to change the procedure. This is not good. Any sugestions on how to now if the user types an integer number in a field? Here's a really simple way: if( ereg( '^[[:space:]]*[[:digit:]]+[[:space:]]*', $input ) ) { // Yaaay, integer input! } Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
On Thu, 2003-10-23 at 11:51, Robert Cummings wrote: On Thu, 2003-10-23 at 11:21, Cesar Cordovez wrote: At this point, I think I have to change the procedure. This is not good. Any sugestions on how to now if the user types an integer number in a field? Here's a really simple way: if( ereg( '^[[:space:]]*[[:digit:]]+[[:space:]]*', $input ) ) { // Yaaay, integer input! } Whoops, forgot the trailing $ if( ereg( '^[[:space:]]*[[:digit:]]+[[:space:]]*$', $input ) ) { // Yaaay, integer input! } Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
Sorry, typo, this is what I meant, !is_integer(12thisisnotanumber) retuns true. but also, is_integer(12) return false. therefore, is_integer(12) return true. So, how can I check if what ever the user writes is an integer or not, knowing that he will write it in a string field. Any how, I solved the problem with preg_match(/^([0-9]+)$/, $value) Thanks for your help, list =) Robert Cummings wrote: On Thu, 2003-10-23 at 11:41, Cesar Cordovez wrote: Because is_integer(12thisisnotanumber) retuns true. Not for me it doesn't. Returns false. Prolly because it's a string. Even the following returns false for me: is_integer(12) Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
* Thus wrote Marek Kilimajer ([EMAIL PROTECTED]): This should be reported as a bug. I tried few searches and I got Warning: mysql_fetch_array(): 9 is not a valid MySQL result resource in /local/Web/sites/php-bugs-web/search.php on line 182 The search seems to work now, what did you search for? Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
Hello all, http://www.php.net/is_numeric is the function you are looking for. No need for fancy regexps. Regards, Greg -- phpDocumentor http://www.phpdoc.org Cesar Cordovez wrote: Sorry, typo, this is what I meant, !is_integer(12thisisnotanumber) retuns true. but also, is_integer(12) return false. therefore, is_integer(12) return true. So, how can I check if what ever the user writes is an integer or not, knowing that he will write it in a string field. Any how, I solved the problem with preg_match(/^([0-9]+)$/, $value) Thanks for your help, list =) Robert Cummings wrote: On Thu, 2003-10-23 at 11:41, Cesar Cordovez wrote: Because is_integer(12thisisnotanumber) retuns true. Not for me it doesn't. Returns false. Prolly because it's a string. Even the following returns false for me: is_integer(12) Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
Status: All Return only bugs in categories: Scripting Engine Problem Return bugs with operating system: windows But it is ok now. Curt Zirzow wrote: * Thus wrote Marek Kilimajer ([EMAIL PROTECTED]): This should be reported as a bug. I tried few searches and I got Warning: mysql_fetch_array(): 9 is not a valid MySQL result resource in /local/Web/sites/php-bugs-web/search.php on line 182 The search seems to work now, what did you search for? Curt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
Cesar, You can take a look into is_numeric () (http://www.php.net/is_numeric). It will tell you whether the value is a number or a numeric string, but it will also return true if the value is a float. However, at that point you know your working with the right type of variable. Jordan S. Jones Cesar Cordovez wrote: Sorry, typo, this is what I meant, !is_integer(12thisisnotanumber) retuns true. but also, is_integer(12) return false. therefore, is_integer(12) return true. So, how can I check if what ever the user writes is an integer or not, knowing that he will write it in a string field. Any how, I solved the problem with preg_match(/^([0-9]+)$/, $value) Thanks for your help, list =) Robert Cummings wrote: On Thu, 2003-10-23 at 11:41, Cesar Cordovez wrote: Because is_integer(12thisisnotanumber) retuns true. Not for me it doesn't. Returns false. Prolly because it's a string. Even the following returns false for me: is_integer(12) Cheers, Rob. -- I am nothing but a poor boy. Please Donate.. https://www.paypal.com/xclick/business=list%40racistnames.comitem_name=Jordan+S.+Jonesno_note=1tax=0currency_code=USD -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
Greg Beaver wrote: http://www.php.net/is_numeric is the function you are looking for. No need for fancy regexps. The OP is looking for an integer, but is_numeric() will return true for float values and also for numbers in scientific notation. So 12.3 and 12E3 will be TRUE. The original $number != intval($number) should work for detecting bad input. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
These are all workarounds around the real problem. If php gets it wrong fix php. Robert Sedlacek wrote: On Thu, 23 Oct 2003 11:59:44 -0400, Cesar Cordovez wrote: So, how can I check if what ever the user writes is an integer or not, knowing that he will write it in a string field. Idea: if(($var + 0) == $var AND is_integer($var + 0)) echo number; Robert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
On Thu, 2003-10-23 at 12:28, Greg Beaver wrote: Hello all, http://www.php.net/is_numeric is the function you are looking for. No need for fancy regexps. Sorry, that doesn't cut it. He want's integers not floats, and I'm also sure he doesn't want exponential notation to pass either. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
On Thu, 2003-10-23 at 12:43, Marek Kilimajer wrote: These are all workarounds around the real problem. If php gets it wrong fix php. Could you explain how PHP has it wrong? Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
On Thu, 2003-10-23 at 12:41, John W. Holmes wrote: Greg Beaver wrote: http://www.php.net/is_numeric is the function you are looking for. No need for fancy regexps. The OP is looking for an integer, but is_numeric() will return true for float values and also for numbers in scientific notation. So 12.3 and 12E3 will be TRUE. The original $number != intval($number) should work for detecting bad input. This doesn't work John, because the the != will convert the $number to an intval for the comparison; however, after reflecting on your code and the style you used.. hte following will work :) $foo = '123fooo'; if( trim( $foo ) != ''.intval( $foo ) ) { echo Not same beast!\n; } else { echo Same beast!\n; } Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
This echoes out Bad on my LAMP server as it should, but Good on Cesar's windows server: $value = 12.3; $number = intval($value); echo Number: $number, Value: $valuebr; // echoes: Number: 12, Value: 12.3 if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } Robert Cummings wrote: On Thu, 2003-10-23 at 12:43, Marek Kilimajer wrote: These are all workarounds around the real problem. If php gets it wrong fix php. Could you explain how PHP has it wrong? Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
On Thu, 2003-10-23 at 13:01, Marek Kilimajer wrote: This echoes out Bad on my LAMP server as it should, but Good on Cesar's windows server: Aaaah how true. I wasn't following this much earlier so I don't know if he is using the most up to date version, in which case it may already be fixed. Cheers, Rob. $value = 12.3; $number = intval($value); echo Number: $number, Value: $valuebr; // echoes: Number: 12, Value: 12.3 if ($number != $value) { echo Bad; } else { echo Good; // echoes Good!! } Robert Cummings wrote: On Thu, 2003-10-23 at 12:43, Marek Kilimajer wrote: These are all workarounds around the real problem. If php gets it wrong fix php. Could you explain how PHP has it wrong? Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval [CONCLUSION]
Everybody: This problem solved. It is not PHP's fault, It is mine. When I fixed some problems that I thought where non intrusive in this problem, everything started working as a charm. Here is the finished function, it is part of a class called xValidate. function integer($msg, $prompt, $value, $min, $max, $name) { $number = intval($value); if ($value == ) { $msg[$prompt] = You have to write a number in this field.; } elseif (!is_numeric($value)) { $msg[$prompt] = The contents of this field should be a number.; } elseif ($value != $number) { $msg[$prompt] = This number should be an integer.; } else { xValidate::number($msg, $prompt, $number, $min, $max, $name); } } and just for the curious here is xValidate::number... function number($msg, $prompt, $number, $min, $max, $name) { if (!empty($min) and ($number $min)) { $msg[$prompt] = This value should be a number greater than or equal to $min.; } elseif (!empty($max) and ($number $max)) { $msg[$prompt] = This value should be a number less than or equal to $max.; } } Thanks for your interest, Cesar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
I got the error again: http://bugs.php.net/search.php?search_for=boolean=0limit=10order_by=direction=ASCcmd=displaystatus=Allbug_type%5B%5D=Scripting+Engine+problemphp_os=windowsphpver=assign=author_email=bug_age=0 Curt Zirzow wrote: * Thus wrote Marek Kilimajer ([EMAIL PROTECTED]): This should be reported as a bug. I tried few searches and I got Warning: mysql_fetch_array(): 9 is not a valid MySQL result resource in /local/Web/sites/php-bugs-web/search.php on line 182 The search seems to work now, what did you search for? Curt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem with intval and !=
* Thus wrote Marek Kilimajer ([EMAIL PROTECTED]): I got the error again: http://bugs.php.net/search.php?search_for=boolean=0limit=10order_by=direction=ASCcmd=displaystatus=Allbug_type%5B%5D=Scripting+Engine+problemphp_os=windowsphpver=assign=author_email=bug_age=0 That reminds me of the time when I had to report a bug about a bug that I couldn't submit because of the bug. that page comes up find for me though. I can reproduce it if I take out a few of the search criteria though. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php