我有以下格式的 .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/>";
}
}