PHP for循环中的换行符

时间:2016-02-17 08:50:20

标签: php html loops for-loop

已经有很多这样的问题,但没有一个答案似乎对我有帮助。我希望在循环的每个输出后都有一个换行符。我使用双引号字符串like I read here,以及使用HTML(因为我希望浏览器也能识别换行符)as I read here

它会创建一个换行符,但只有低于完整输出。

我无法在循环输出之间创建换行符。基本上我得到一个文本块然后换行。

这是我正在使用的循环:

<?php
include_once('simple_html_dom.php');
$target_url = "http://www.buzzfeed.com/trending?country=en-us";
$html = new simple_html_dom();

$html->load_file($target_url);

$posts = $html->find('ul[class=list--numbered trending-posts trending-posts-    now]');
$limit = 10;
$limit = count($posts) < $limit ? count($posts) : $limit;
for($i=0; $i < $limit; $i++){
  $post = $posts[$i];
  $post->find('div[class=trending-post-text]',0)->outertext = "";
  echo strip_tags($post, '<p><a>') . "<br/>\n";
}

我还尝试了"\r\n"和一系列变体,以及nl2br() function。我相信PHP_EOL命令仅适用于我所研究的命令行。

我是PHP的绝对初学者,所以我可能错过了一些简单的东西,但我无法弄清楚。

编辑: 这是它打印的内容: http://globalsocialnews.com/crawler/test8.php

我还提供了完整的代码以防万一。

2 个答案:

答案 0 :(得分:2)

你可以使用css实现进行换行... 像:

.rcorners1 a {
    display: block;
    margin-bottom: 10px;//for show extra margin between each line...  

    }

编辑:使用margin css属性获得额外的保证金......

请尝试实施此...

答案 1 :(得分:1)

更好地使用

echo "</br>";