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;
}