2013-02-24 15 views
0

我有一個文本文件,它看起來像以下:如何從具有標題或元標記的文本文件回顯行?

http://tisue.net/jandek/live.html 
<title>Jandek: Live</title> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 


http://news.nationalgeographic.com/news/2004/06/0629_040629_camelspider.html 
<title>Camel Spiders: Behind an E-Mail Sensation From Iraq</title> 
<meta name="description" content="A photo of a U.S. soldier in Iraq holding massive, hairy, supposedly flesh-eating spiders has been burning up e-mail in-boxes around the world. The arachnids (called camel spiders or wind scorpions) are real, but scientists say many claims about them are anything but."> 

和幾千更像。

我正在使用fopen()fgets()來讀取每一行並對其進行回顯。問題是<title><meta />未被回顯;線條返回空白。我怎樣才能讓php看到這些純文本並回顯它們?

編輯:下面是我使用的代碼:

$handle = fopen($myFile, 'r'); 

while(!feof($handle)){ 

    $data = fgets($handle); 
    echo $data; 
+0

什麼是代碼? – 2013-02-24 09:21:19

+0

向問題添加了代碼,謝謝。 – Phil 2013-02-24 09:24:39

+0

該代碼應該可以正常工作。您是否使用瀏覽器進行檢查? – 2013-02-24 09:25:23

回答

3

您需要查看網頁的源代碼中看到<title><meta>標籤。這可以通過右鍵單擊頁面並在大多數瀏覽器中單擊view-source來實現。

或者使他們在HTML可讀利用htmlspecialchars

$handle = fopen($myFile, 'r'); 

while(!feof($handle)){ 

    $data = fgets($handle); 
    echo htmlspecialchars($data); 
0

你首先需要檢查渡過頁面有要退出的meta標籤,你可以轉換的標籤。 這可以用get_meta_tags()來完成,這裏有更多的信息http://php.net/manual/en/function.get-meta-tags.php

並且爲了讀取每行使用file()來逐行讀取它。

<?php 
$lines = file("fileurl"); 
foreach($lines as $line) 
{ 
    echo($line); 
} 
?> 
相關問題