我正在努力,但做不到。任何PHP专家都在那里分享知识...(我真的很想知道Facebook是如何使用PHP构建的,如果我不能做这个简单的事情:)坏真的很坏)
我有下面的文本文件(示例.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 读取上面的示例.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)
这里的东西在样本中.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.