0
我使用base64_decode將十六進制值解碼爲其原始內容並將其逗號中的字符串用作數組。打印數組顯示成功,但是當我嘗試使用switch()的值並且它不工作時。我嘗試使用intval()將數字字符串更改爲整數,並返回0.我認爲這與解碼有關,但我不知所措。我也知道,我有一些字符在十六進制值的開頭不會解碼PHP intval或int類型轉換在使用base64_decode解碼的十六進制字符串時失敗
在我的代碼$ value是我的十六進制字符串來自解析一個SimpleXMLElement()我有一個十六進制有效載荷數組,我循環通過與一個foreach這是窺測一個循環:
//the hex value im decoding comes from parsing my SimpleXMLElement
//I generate $value = gAExLDUyLjMxOTEsLTExMy45ODc=
//decode it and it gives me a strange character a question mark in a diamond
//diamond thing should decode to "[128][3]" but that doesn't come across.
$result = base64_decode(str_replace(" ","+",$value));
//I trim off the strange character
$result = substr($result,1);
//and get the expected string
//1,52.3191,-113.9870
//so I explode it into an array
$param = explode(',', $result);
// can verify the array with print_r -- all good
//but this type cast fails so does intval()
$type = (int)$param[0];
//this is all going on inside a foreach loop
//so the decoded value is different everytime and
//i have different operations to perfrom based
//on the value of $type variable using the switch
//cant get the switch to accept the type variable
我想在開始的兩個字節,但是我我無法將它們解碼爲可讀的數據。 (int)typecast和intval()失敗的任何想法? – Laurence
@Laurence您要轉換爲int的字符串包括字符串開頭的兩個字節(之一)。因此,它看起來不像一個數字,所以PHP給你0. – IMSoP
謝謝!這就是爲什麼我的intval()失敗。我希望我知道如何解碼這些第一個字節,但這仍然會讓球繼續滾動。 – Laurence