duanliujie8639 2016-02-17 08:50
浏览 280

PHP for循环中的换行符

There have been a bunch of questions like this already, but none of the answers seem to help me. I would like to have a line-break after each output from a loop. I am using double-quoted strings, like I read here, as well as using HTML (because I want the browser to recognize the line-breaks too) as I read here.

It does create a line-break, however only below the complete output.

I cannot manage to create a line-break between the outputs of the loop. Basically I get a block of text and then a linebreak.

Here is the loop I am using:

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


$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/>

I've also tried " " and a bunch of variations, as well as the nl2br() function. I believe the PHP_EOL command is meant only for the command line, from what I've researched.

I'm an absolute beginner with PHP, so I am probably missing something simple, but I can't figure it out.

EDIT: Here is what it prints: http://globalsocialnews.com/crawler/test8.php

I also included the complete code in case that helps.

  • 写回答

2条回答 默认 最新

  • dqhmtpuy94946 2016-02-17 09:12

    You can do line break using css implementation ... like:

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

    Edit: Use margin css attribute for extra margin...

    please try implementing this...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 关于#ar#的问题:/* User can add his own implementation to report the HAL error return state */(语言-c语言)
  • ¥15 ImportError: DLL load failed while importing _iterative: 找不到指定的模块。
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败