simbawoomba Posted January 4, 2007 Share Posted January 4, 2007 hii am tryint to convert a string to an integer, i have the following codefunction strtoint($str) { $ip = 0; $tetr = explode(".", $str); for ($i = 0; $i < 4; $i++) { $ip = $ip << 8; $ip += $tetr[$i]; }; return $ip; } <select size="10" id="templateList" name="templateList" onchange="<?php $a = strtoint('templateList.value'); echo 'displayTemplate('.$templateArray[$a][1].',MessageTemplate)'; ?> ">;however $a is always equal to 0. templateList.value can be equal to "0" or "1" (up to any value) ect however it always comes out as 0 can someone please helpthanks in advance Link to comment https://forums.phpfreaks.com/topic/32825-string-to-int-updated-with-more-info/ Share on other sites More sharing options...
hvle Posted January 4, 2007 Share Posted January 4, 2007 I think your function strtoint should be iptoint.In case you wanted to convert an ip4 to an integer, there exist a function 'ip2long' of PHP to do that for you.echo ip2long('192.168.1.1'); // -1062731519this echo a negative number because i'm using window. in Unix server, it will be correct Link to comment https://forums.phpfreaks.com/topic/32825-string-to-int-updated-with-more-info/#findComment-152908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.