繁体   English   中英

使用php读取文本文件(特定行)

[英]read text file using php (particular line)

我正在努力但却无法做到这一点..任何PHP专家分享那里的知识...(我真的很想知道facebook如何使用PHP构建,如果我不能做这个简单的事情:)坏真的很糟糕)

我有下面的文本文件(sample.txt)

<Module>
title = "this is title" thumb ="http://www.example.com/thumb.jpg"
description ="this is the description of the title" 
screen ="http://www.example.com/screen.jpg"
<Content type="html" view="canvas">
<![CDATA[ 
<div>Hello world Canvas view</div>
<script type="text/javascript">

function goToView(dest) {
  var supported_views = gadgets.views.getSupportedViews();
  gadgets.views.requestNavigateTo(supported_views[dest]);
};
</script>
 <a href="javascript:goToView('home')" >Go to home view</a><br><br>
 ]]> 
 </Content>
 </Module>

现在我想使用php阅读上面的sample.txt文件并将其显示或存储在数据库中。

例如

this is title - should go in $title variable
http://www.example.com/thumb.jpg  - should go in $thumb variable 
i just want only these four variables (title, thumb, description & screen) 

这里的东西是在sample.txt中,以上四个变量(标题,拇指,描述和屏幕)都可以在单独的行中或在同一行上。

任何专家可以帮助我,我尝试了很多,但没有运气...

先感谢您..

如果将变量保存在ini文件中,例如: sample.ini

title = "this is title" 
thumb = "http://www.example.com/thumb.jpg"
description = "this is the description of the title" 
screen = "http://www.example.com/screen.jpg"

您可以使用parse_ini_file()获取变量。

$vars = parse_ini_file('sample.ini');
echo $vars['title'];
echo $vars['thumb'];
// etc.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM