2012-06-15 4 views
0

열심히 노력하고 있지만 할 수 없습니다. 모든 PHP 전문가가 지식을 공유합니다 ... (필자는 페이스 북이 PHP를 사용하여 빌드 된 방법에 대해 궁금합니다. 이 간단한 일이 : 나쁜 정말 나쁜)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 파일에 변수를 저장하는 경우

는 전문가

+1

무엇을 시도 했습니까? – Sanjay

답변

2

..

가 사전에 감사 ... 내가 많이하지만 행운을 시도 나를 도울 수 예 : 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. 
+0

답장을 보내 주셔서 감사합니다. 그러나 sample.text에는 다른 많은 것들이 많이있을 수 있습니다. title = "this is title"thumb = "http://www.example.com/thumb.jpg" description = 화면 = "http://www.example.com/screen.jpg"것 그 일이 시나리오에서

skfjsdf saf ksdfj asfdl
"이 제목에 대한 설명은"? – SmartDev

+0

당신은'$ body = "

skfjsdf saf ksdfj asfdl
"'와 같은 변수에 HTML을 할당 할 수 있습니다. 하지만 PHP 로직과 HTML 프리젠 테이션을 분리해야한다고 생각합니다. – flowfree

+0

감사하지만 그 파일에 대한 통제권이 없다 ... 나는 질문을 업데이트했다. – SmartDev

관련 문제