簡體   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