Reading Every Two Characters In A String
Posted: Sat Sep 12, 2009 4:57 pm
I have a string that is like this: 'FF336AD0075CCC'. $msg_len = strlen of this string.
I need to loop through and get every 2 characters in the string and convert it to decimal. Here is what I have but it returns a syntax error.
I need to loop through and get every 2 characters in the string and convert it to decimal. Here is what I have but it returns a syntax error.
Code: Select all
for ($msgCnt=1; $msgCnt<=$msg_len; $msgCnt +=2) {
$hxChar=substr($keyWordString, $keyCnt-1,2);
$hxVal=hexdec($hxChar);
$msg_writ=$msg_writ.chr($hxVal);