0

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:

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

I've also tried "\r\n" 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.

7
  • Can you show what it prints? Commented Feb 17, 2016 at 8:52
  • Can you paste the output somewhere? Commented Feb 17, 2016 at 8:52
  • "It does create a line-break, however only below the complete output." Put the <br /> after the } that closes the for loop Commented Feb 17, 2016 at 9:03
  • You have an error in your code example: Parse error: syntax error, unexpected '<' in /home/jasperko/public_html/globalsocialnews.com/crawler/test8.php on line 51 Commented Feb 17, 2016 at 9:05
  • 1
    I tried both and neither worked out. Ashish below had an answer which worked for me in the end Commented Feb 17, 2016 at 9:25

2 Answers 2

2

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...

Sign up to request clarification or add additional context in comments.

1 Comment

this worked! is there also a way to add another linebreak to this?
1

Better Use

echo "</br>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.