holladb Posted December 5, 2007 Share Posted December 5, 2007 I have a variable being sent over and i need to grab the first 2 characters...i've tried a couple different things but nothing seems to work. Here is what i had last: $code1 = $_POST['code1']; $a = count_chars($code1, 2); foreach (count_chars($code1,1) as $i => $val) { $item .= chr($i).","; } //$item = sort($item); $c = array($item); echo $c; echo $item; //echo "<b>".$1."<b>".$2; echo $a; Now this way works in the sense that it puts it in an array and i will be able to explode it and list each variable but it mixes up the format. For instance if the post variable of code1 was AB12 it would put 21ba. So that wont work. Anybody have a solution?? Link to comment https://forums.phpfreaks.com/topic/80211-issue-with-2/ Share on other sites More sharing options...
bibby Posted December 5, 2007 Share Posted December 5, 2007 why not just sub-string ? http://www.php.net/manual/en/function.substr.php $firstTwo = substr($_POST['string'], 0, 2); Link to comment https://forums.phpfreaks.com/topic/80211-issue-with-2/#findComment-406585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.