ali_2kool2002 Posted February 19, 2007 Share Posted February 19, 2007 Hi can some1 code how i can convert a value in an input box retrieved from using post to an integer value in php?? thanks if ne 1 can help me ... :-* Quote Link to comment https://forums.phpfreaks.com/topic/39220-solved-converting-string-to-int/ Share on other sites More sharing options...
tom100 Posted February 19, 2007 Share Posted February 19, 2007 If it's an actual integer value, PHP will automagically convert it to an integer. You could check if it is a digit or not by using if (ctype_digit($value)) Quote Link to comment https://forums.phpfreaks.com/topic/39220-solved-converting-string-to-int/#findComment-188960 Share on other sites More sharing options...
ali_2kool2002 Posted February 19, 2007 Author Share Posted February 19, 2007 im confused to your explanation sorry,, im entering it into my database which has a attribute of type integer,, but jus need 2 make sure i can enter integer values from the input box which is of course type text so need somethin to convert say my variable $x which is string to integer..... could anyone use the variable $x in their code to make it easier to understand plz thnx Quote Link to comment https://forums.phpfreaks.com/topic/39220-solved-converting-string-to-int/#findComment-188964 Share on other sites More sharing options...
Jessica Posted February 19, 2007 Share Posted February 19, 2007 you can use intval() to get the integer value, or is_numeric to check if it is. Quote Link to comment https://forums.phpfreaks.com/topic/39220-solved-converting-string-to-int/#findComment-188972 Share on other sites More sharing options...
printf Posted February 19, 2007 Share Posted February 19, 2007 Read the manual, it's self explained, PHP by default is a loosed type language, but it also support dynamic casting, so you should always cast an integer! http://us3.php.net/manual/en/language.types.integer.php#language.types.integer.casting printf Quote Link to comment https://forums.phpfreaks.com/topic/39220-solved-converting-string-to-int/#findComment-188973 Share on other sites More sharing options...
konnwat Posted February 19, 2007 Share Posted February 19, 2007 <?php $var = 1*$var; ?> quite simple just do some maths with a string and if its a number it will turn into a float/int Quote Link to comment https://forums.phpfreaks.com/topic/39220-solved-converting-string-to-int/#findComment-188976 Share on other sites More sharing options...
ali_2kool2002 Posted February 19, 2007 Author Share Posted February 19, 2007 ok im getting this error as its stil not converting to int,,, Out of range value adjusted for column 'sel_item_qty' at row 1 i know i need 2 use intval() but does my variable $x go inside the brackets so its intval($x) ; ? Quote Link to comment https://forums.phpfreaks.com/topic/39220-solved-converting-string-to-int/#findComment-188981 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.