對於一個有趣的項目,我想在PHP中創建一個二進制時鐘,所以基本上爲了簡單起見,我使用date("H:m:s");
來獲取字符串格式的時間,然後使用str_split();
將每個字符串字母分隔成一個數組。PHP:無法將字符串轉換爲int?
我的代碼是在這裏與它的工作:如果我嘗試這兩個解決該問題
$time = str_split($time);
//I tried $time = array_map(intval, $time); here but no dice
$tarray = Array(
//hh:mm:ss = [0][1][3][4][6][7]
str_pad(decbin((int)$time[0]), 8, STR_PAD_LEFT), //I tried casting to (int) as well
str_pad(decbin($time[1]), 8, STR_PAD_LEFT),
str_pad(decbin($time[3]), 8, STR_PAD_LEFT),
str_pad(decbin($time[4]), 8, STR_PAD_LEFT),
str_pad(decbin($time[6]), 8, STR_PAD_LEFT),
str_pad(decbin($time[7]), 8, STR_PAD_LEFT),
);
不管,結果數組是例如以下(有小數旁邊的清晰度):
10000000 -> 128
10000000 -> 128
10000000 -> 128
00000000 -> 0
10000000 -> 128
10010000 -> 144
爲什麼那些不是1-9的二進制文件?
您忘記了提問。 – zerkms 2010-10-04 05:22:06
@zerkms,太忙了寫細節。 :P謝謝。 – John 2010-10-04 05:24:40