循环回显file_get_contents

Echo file_get_contents in a loop

我在核心目录中有一些文件。文件名示例:1 2 3 4 5 6 7 8 9 10 ... 我想将它们回显为 (loop):

content of file 1

content of file 2

content of file 3

content of file 4

content of file 5

content of file 6

............

............

我尝试了以下代码,但它不起作用。 请帮忙!

<?php
for ($i=1; $i<=10; $i++)
{
$x=file_get_contents('core/$i');
echo $x . '<br>';
}
?>

您正在通过在 ''

中提及将 $i 设置为文本类型

将代码更改为

<?php
for ($i=1; $i<=10; $i++)
{
$x=file_get_contents('core/'.$i);
echo $x . '<br>';
}
?>