woody79 Posted June 20, 2007 Share Posted June 20, 2007 this is a string: $number = "9"; this is a number: $number = 9; I need to get a string into a number because i am grabbing the number using the GET funtion Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/ Share on other sites More sharing options...
redarrow Posted June 20, 2007 Share Posted June 20, 2007 so add a varable to the get. <?php $number=$_GET['the_number']; echo $number; ?> $number holds 9 Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/#findComment-278264 Share on other sites More sharing options...
chigley Posted June 20, 2007 Share Posted June 20, 2007 <?php $number = "9"; $number = intval($number); // $number = 9; ?> Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/#findComment-278388 Share on other sites More sharing options...
woody79 Posted June 24, 2007 Author Share Posted June 24, 2007 Okay, <?php $number = "9"; $number = intval($number); // $number = 9; ?> that didn't work and i tried intval like this $number = intval($_GET['myNumber']); echo $number; $number++; $number did not increment Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/#findComment-281159 Share on other sites More sharing options...
cooldude832 Posted June 24, 2007 Share Posted June 24, 2007 thats because you incremented number after oyu echoed it Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/#findComment-281162 Share on other sites More sharing options...
JustinK101 Posted June 24, 2007 Share Posted June 24, 2007 You might be able to do this as well: $number = (int)$_GET['myNumber']; $number++; echo $number; Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/#findComment-281164 Share on other sites More sharing options...
cooldude832 Posted June 24, 2007 Share Posted June 24, 2007 i think there is a difference in what is an int and whats a string in php 4/5 Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/#findComment-281166 Share on other sites More sharing options...
JustinK101 Posted June 24, 2007 Share Posted June 24, 2007 I think it works either way. I just tested incrementing a string with 12 in it, and it worked. Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/#findComment-281170 Share on other sites More sharing options...
woody79 Posted June 24, 2007 Author Share Posted June 24, 2007 thanks JustinK101, I forgot to mention i was using it in a loop Link to comment https://forums.phpfreaks.com/topic/56323-solved-php-string-to-number/#findComment-281198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.