次の形式の .txt ファイルがあります。
topic: My Thesis | link: my_thesis.html | date: 04-01-2013, 06:01 AM ~ postedby: smith ~ post: Has anyone worked on my thesis? ~
topic: Thesis Submission | link: thesis_submission.html | date: 05-10-2013, 08:20 PM ~ postedby: Terry ~ post: Anyone is working on thesis submission? ~ date: 05-11-2013, 10:04 AM ~ postedby: Julia ~ post: Working on it, will submit today at any time ~ date: 05-11-2013, 04:25 PM ~ postedby: Terry ~ post: Please get reviewed before submission, Thanks! ~ date: 05-11-2013, 10:00 PM ~ postedby: Smith ~ post: Hurryup We don't have time, Its already late ~
この方法で出力を取得しようとしましたが、達成できませんでした。誰でも私を助けてもらえますか?
トピック: 私の論文
リンク: my_thesis.html
日付:04-01-2013, 06:01 AM
投稿者:smith
投稿:私の論文に取り組んだ人はいますか?
トピック:...
リンク:..
日付:...投稿
者:...
投稿:...
日付:...投稿
者:...
投稿:...
.....
.....
これが私のコードです
$text = file_get_contents('c:\textfile.txt');
$texts = explode("\n",$text);
foreach($texts as $line) {
$temp = explode('topic:',$line);
$topic = explode("|",$temp[1]);
echo "topic : " .$topic[0] ."<br/>";
$temp = explode('link:',$line);
$href = explode("|",$temp[1]);
echo "link : " .$topic[0] ."<br/>";
$add = explode("|",$line);
$adds = $add[2];
$rem = explode("\n",$adds);
foreach($rem as $data) {
$temps = explode('date:',$data);
$date = explode('~',$temps[1]);
echo "date : " .$date[0] ."<br/>";
$temps = explode('postedby:',$data);
$postedby = explode('~',$temps[1]);
echo "postedby: " .$postedby[0] ."<br/>";
$temps = explode('post:',$data);
$post = explode('~',$temps[1]);
echo "post: " . $post[0] ."<br/>";
}
}