我有一個包含數組列表的文本文件:如何轉換的文本文件陣列的列表爲實際陣列在PHP
'1920s' => array('20s','twenties')
'1930s' => array('30s','thirties')
'1940s' => array('40s','forties')
'1950s' => array('50s','fifties')
我想導入爲數組的數組,像這樣:
Array
(
[1920s] => Array
(
[0] => 20s
[1] => twenties
)
[1930s] => Array
(
[0] => 30s
[1] => thirties
)
[1940s] => Array
(
[0] => 40s
[1] => forties
)
[1950s] => Array
(
[0] => 50s
[1] => fifties
)
)
我導入文件:
$decadesFile = file_get_contents('/Users/derwood/capsule/decades.txt');
$decades = explode("\r",$decadesFile);
,但我得到的文本行的數組:
Array
(
[0] => '1920s' => array('20s','twenties')
[1] => '1920s' => array('20s','twenties')
[2] => '1940s' => array('40s','forties')
[3] => '1950s' => array('50s','fifties')
除了「file_get_contents」和「explode」我還有其他的組合嗎?
編輯:我確實閱讀了列出的答案,但文本文件是由FMP數據庫生成的,而不是print_r輸出,所以憑藉我有限的經驗,我不認爲問題是重複的。然而,這裏的鏈接問題和答案對於說明它們之間的關係非常有幫助。謝謝。
第1行丟失分號。 –
@theFX謝謝你:) – georoot
這照顧了它。我不得不增加幾行輸出來解釋更長的記錄,但它的工作。謝謝。 :) –