PHP有多種方法可以讀取文件內容:
$file = fopen("file.txt", "r");
if ($file) {
while (($line = fgets($file)) !== false) {
echo $line;
}
fclose($file);
}
$content = file_get_contents("file.txt");
echo $content;
$file = fopen("file.txt", "r");
if ($file) {
while (($line = fgets($file)) !== false) {
echo $line;
}
fclose($file);
}
$lines = file("file.txt");
foreach ($lines as $line) {
echo $line;
}