-2

我正在使用文本文件,我将每天更新文本文件。所以我希望这些文本在带有格式的 html 文件上。如何使用文本文件生成 html 文件?谁能帮我?

4

3 回答 3

1

取决于您是否要设置 txt 文件中的段落或每一行的样式,

如果每一行,那么你可以有:

$myfile = 'filetoread.txt';
$lines = file($myfile);    
for($i=count($lines);$i>0;$i--){
    echo "<span class='yourstyleclass'> $lines[$i] </span>";
}

if paragraphs

$myfile = 'filetoread.txt';
$lines = file($myfile);

$lines = str_replace(array("\n\n", "\n\r"), "</p><p>", $lines);
echo "<p>$lines</p>";
于 2012-11-05T08:47:51.497 回答
0

采用file_get_contents($file_location)

请访问: http: //php.net/manual/en/function.file-get-contents.php

于 2012-11-05T07:26:49.227 回答
0

假设您在“text_file.txt”中有这个:

<div>
<h1>Header</h1>
<p>Some short paragraph...</p>
</div>

您需要做的就是:

echo file_get_contents("text_file.txt");
于 2012-11-05T07:30:15.943 回答