PHP new line \n and \r\n not working

后端 未结 3 541
南方客
南方客 2021-01-11 17:18
  $rows = mysql_num_rows($result) ;
  for ($j=0 ; $j < 3 ; $j++) {
  for ($i=0 ; $i < 3 ; $i++) {
    $row = mysql_fetch_array($result) ;
    echo \'

        
相关标签:
3条回答
  • 2021-01-11 17:57

    Your echo "\r\n"; is outside the loop. Move it inside the loop.

    Also, if you want the line breaks to be visible in the browser, you should print a <br /> too.

      $rows = mysql_num_rows($result) ;
      for ($j=0 ; $j < 3 ; $j++) {
      for ($i=0 ; $i < 3 ; $i++) {
        $row = mysql_fetch_array($result) ;
        echo '<a href="image2.php?id='.$row['ID'].'">'."<img src='".$row['Image']."' />".'</a>' ;
      }
        echo "<br />\n";    
      }
    
    0 讨论(0)
  • 2021-01-11 18:04

    You need:

    echo '<br />';
    

    instead of:

    echo "\r\n";
    
    0 讨论(0)
  • Whitespace is not displayed verbatim when it's part of HTML text. \r and \n are not universal constants; they are just characters, and it's up to whatever program consumes them to decide what to do with them.

    You should use <br> instead.

    0 讨论(0)
提交回复
热议问题