今天,我了解了如何将文件分解为碎片。我用下面这段代码完成了这项工作。
<?php
$file = file('url here');
foreach ($file as $files)
{
list($example) = explode(',', $file);
}
?>但是当我回显数组时,我只得到一个文本“$example”作为输出。我输入的文本文件如下所示
1,2,3,4,5
我希望输出结果如下所示
1
2
3.
4.
5
所以有没有可能。如果是,请帮帮我
发布于 2012-06-18 01:31:41
这是因为$example是一个数组。这就是为什么会返回"Array“。改为按如下方式打印:
foreach($example as $item) echo $item,"\n";发布于 2012-06-18 01:28:55
对于HTML,在每个项目后使用<br>;对于文本文件,在每个项目后使用PHP_EOL
foreach ($example as $item)
{
echo "$item<br>".PHP_EOL;
}发布于 2012-06-18 01:31:14
$example将是一个数组,因此您需要使用print_r()或指定索引来回显:
echo $example[1];理想情况下,要打印所有元素,您可以简单地执行另一个循环:
foreach($example as $element){echo $element."<br>";}https://stackoverflow.com/questions/11073347
复制相似问题