0
我想了解如何最好分解我擁有的某些數據。無論是分成多個單獨的數組還是嵌套數組,或者不同的東西。按特定字符劃分文檔,然後再劃分爲變量字段
我有一個文件包含多個不同項目的標題,文件名和日期。每一項都與性格^
分離,列表中的每個部分帶有一個波浪線分離~
文件看起來是這樣的:
Example post one~example-post-one~Friday 17 October 2014^
Wayfinding For The Mobile Web~wayfinding-for-the-mobile-web~Friday 17 October 2014^
我已經創建了抓取數據和功能分離出來進入使用^
作爲delimter數組:
function getPostList(){
$masterposts = "../posts/master-allposts.txt";
$current = file_get_contents($masterposts);
$masterpostlist = explode('^', $current);
return $masterpostlist;
}
,結果是這樣的:
array(3) { [0]=> string(46) "Example post one~example-post-one~Friday 17 October 2014" [1]=> string(83) " Wayfinding For The Mobile Web~wayfinding-for-the-mobile-web~Friday 17 October 2014" [2]=> string(0) "" }
但是,我現在試圖進一步分解該數組,所以我可以輸出每個單獨的部分。理想情況下,字符串變形$title, $filename and $publishdate
我得到了這麼遠,但我想我遇到了問題,因爲我可能每次覆蓋數組。你會如何做到這一點?
foreach ($masterpostlist as $post){
$postParts = explode('~',$post);
var_dump($postParts);
}
我有點困惑,如何使用這個。我如何獲取帖子的各個部分並將它們輸出到單個變量中? – Francesca 2014-10-17 14:57:34
查看第二個樣本。就像你過去一樣使用你的功能。 – ToBe 2014-10-17 15:00:41