问题
I have a simple text file. The file name is kpop.txt - What I want to do is include the contents of the file in a webpage. I am using php for includes (header / footer stuff).
I would like the contents of the kpop.txt file to remain formatted similar to it's current form. The only real difference that I would like to make is to increase the font size.
I am currently using
<?php
include("kpop.txt");
?>
I have also tried
<pre>
<font size ="12">
<?php
include("kpop.txt");
?>
</font>
</pre>
What I want to see is my text like this but simply with a larger font.
FTUS43 KGGW 271140
TAF
KP01 271140Z 2706/2806 08010KT P6SM SCT140
FM271500 12011KT P6SM SCT110
FM271900 14011KT P6SM BKN120
FM280000 14008KT P6SM VCSH BKN100
FM280300 13006KT P6SM VCSH SCT100
AMD NOT SKED. UNFL=
TAF
KM75 271140Z 2706/2806 07008KT P6SM SCT110
FM271500 11008KT P6SM FEW150
AMD NOT SKED. UNFL=
Another solution that did not work is
<?php
myfilename = "kpop.txt";
$TAF = file_get_contents(myfilename);
$TAFlines = explode("\n", $TAF);
//echo $TAF;
echo $TAFlines;
}
?>
I have also tried using the file_get_contents function along with an explode function but cannot seem to get that to work properly. Any help is greatly appreciated.
回答1:
I would suggest you use CSS, rather than the deprecated <font> tag:
<pre style="font-size:120%">
<?php echo file_get_contents('kpop.txt') ?>
</pre>
回答2:
So this is what I came up with.
<pre>
<?php
//Read in the file and increase the font 200%
$TAF = file_get_contents("kpop.txt");
echo "<div style='font-size:200%'><p>$TAF</p></div>";
?>
</pre>
It may not be pretty but it works. Thank you all for your help.
回答3:
It's pretty simple, use fopen() and then read it fread(),just use echo to display it:
<?php
$myfile = fopen("kpop.txt", "r") or die("Unable to open file!");
echo '<span style="font-size:30px;">' . fread($myfile,filesize("kpop.txt"))
. ' </span>';
fclose($myfile);
?>
More details: https://www.w3schools.com/php/php_file_open.asp
来源:https://stackoverflow.com/questions/45360673/php-include-text-file-and-format