2012-06-25 60 views
0
<?php 
$player = $_GET['player']; 
$data = explode(" ", file_get_contents("http://hiscore.runescape.com/index_lite.ws?player={$player}")); 
print_r($data); 
?> 

出於某種原因,這將返回爆炸()困惑我

Array ([0] => 322788,1584,39425065 474211,75,1213741 424332,73,1044331 497032,75,1223804 518140,74,1127869 622836,53,146813 484601,51,114656 540925,65,452516 276405,78,1772587 614588,62,339049 85477,99,13069655 135438,86,3702239 69906,99,13034532 376565,60,294135 403376,55,173156 413268,62,349011 339269,50,103575 388661,52,125891 452907,52,134281 402625,50,102104 281390,50,109948 236592,63,377586 385212,50,103894 329955,50,104225 320731,50,103833 286842,50,101634 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1) 

通過file_get_contents檢索到的原始數據是

322790,1584,39425065 474214,75,1213741 424335,73,1044331 497037,75,1223804 518145,74,1127869 622844,53,146813 484604,51,114656 540930,65,452516 276407,78,1772587 614595,62,339049 85477,99,13069655 135439,86,3702239 69906,99,13034532 376567,60,294135 403379,55,173156 413272,62,349011 339272,50,103575 388664,52,125891 452909,52,134281 402629,50,102104 281392,50,109948 236593,63,377586 385216,50,103894 329957,50,104225 320733,50,103833 286843,50,101634 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 

我看不出爲什麼這是行不通的。測試它,explode(" ", "The cat is happy")完美。

任何想法?

+0

非換空間? – biziclop

+0

數據是不可能被空格分隔的?但是一個不同的(相似的)字符,比如U + 160? '''''或' ' –

+0

如果您向我們提供您的API調用結果,我們可以不再猜測。 –

回答

5

原始數據由線無法相依打破(看該頁面的源代碼,你會看到類似:

369410,1491,41557372 
670285,60,285887 
777347,41,44705 
399433,80,2132002 
263342,89,4893081 
86022,99,13097638 
472647,52,123827 
278652,84,3165705 
454958,66,517025 
706040,53,137563 
445967,61,328458 
382124,68,642361 
362084,66,534339 
96,62,342446 
412791,54,164607 
475061,60,279628 
331177,50,107107 
332564,56,199183 
21509,99,13217389 
371340,53,148963 
314233,46,68904 
463762,44,55836 
128963,73,1034979 
569897,20,4784 
500492,19,4088 
412997,36,26867 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 
-1,-1 

嘗試通過爆炸

explode("\n", ...); 
+0

謝謝你,我的愚蠢的錯誤。 – Steve

-1
var_dump(
    explode(',', 
     str_replace("\n", '', 
      file_get_contents("http://hiscore.runescape.com/index_lite.ws?player={‌​$player}" 
      ) 
     ) 
    ) 
); 
+0

可怕的想法。它會合並行結尾和行首的整數。即:',41557372 \ n670285,'會變成',41557372670285,'。如果有的話,做'str_replace(「\ n」,',',...' –

+0

不知道輸入,不關心..即使如此,顯然%3將解決「問題」,除非有是沒有-1,-1,我沒有看到之前,我的回答... –

-1

您試圖用空格分解,但原始數據饋送中沒有空格。

這完全是逗號分隔,所以嘗試:

$lines = explode("\n", $data); 
foreach($lines as $line){ 
    $values = explode(",", $line); 
} 
+0

絕對有絕對是空格.. – Steve

+1

更新回答迴路,但沒有空格,這些是換行符。'「」!= 「\ n」' –