www.webdeveloper.com
Results 1 to 9 of 9

Thread: New line in php?

  1. #1
    Join Date
    Mar 2005
    Posts
    172

    New line in php?

    hi,

    Can anyone please tell me how to make a new line in php:

    PHP Code:
    echo "<tr>";
    echo 
    "<td><input type='checkbox' name='d$n' value='"$row->news_id."'></td>";
    echo 
    "<td>$row->formatted_date</td>";
    echo 
    "<td>"stripslashes($row->headline) ."</td>";
    echo 
    "<td>"stripslashes($row->season) ."</td>"
    I know it's adding /n to each line, but that's returning pesky errors?

    Thanks

  2. #2
    Join Date
    Mar 2007
    Posts
    946
    PHP Code:
    echo "<tr>";
    echo 
    "<td><input type='checkbox' name='d$n' value='"$row->news_id."'></td>";
    echo 
    "<td>$row->formatted_date</td>";
    echo 
    "<td>"stripslashes($row->headline) ."</td>";
    echo 
    "<td>"stripslashes($row->season) ."</td>"
    It is a back slash not a forward slash and it needs to be in double quotes.

    Like this
    PHP Code:
    echo "Add a new line \n"
    Not like this
    PHP Code:
    echo "This doesn't not work /n"

  3. #3
    Join Date
    Mar 2005
    Posts
    172
    Thanks,

    But say I was echoing a variable?

    PHP Code:
    echo "$pagelinks"

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,536
    PHP Code:
    echo "$pagelinks\n";
    //...or...
    echo $pagelinks "\n"
    Note that the "\n" must be in double quotes, as it does not have this special meaning within single quotes.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Nov 2007
    Posts
    53
    what works for me also is a return character (\r) with a newline character(\n)
    so it would be: \r\n

    and dont forget that escape characters must be within quotes

  6. #6
    Join Date
    Aug 2013
    Posts
    1
    try this:
    PHP Code:
    echo "<br>"
    this provides an HTML new line

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,407
    Use the PHP_EOL which will automatically be \r\n or \n depending on if the server is windows or a linux installation.

    http://php.net/manual/en/reserved.constants.php

    If you have a document that you want displayed in a web browser page (but not in a text area) then use nl2br() function to convert all newlines in to <br /> tags.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  8. #8
    Join Date
    Apr 2010
    Posts
    227
    echo "<td>". stripslashes(nl2br($row->season))."</td>";

  9. #9
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,407
    I think that the OP is looking for this type of thing...

    PHP Code:
    echo "<tr>" PHP_EOL;
    echo 
    "<td><input type='checkbox' name='d$n' value='"$row->news_id."'></td>"PHP_EOL;
    echo 
    "<td>$row->formatted_date</td>"PHP_EOL;
    echo 
    "<td>"stripslashes($row->headline) ."</td>"PHP_EOL;
    echo 
    "<td>"stripslashes($row->season) ."</td>"PHP_EOL
    an alternative is to


    PHP Code:
    $out = array("<tr>",
    "<td><input type='checkbox' name='d$n' value='"$row->news_id."'></td>",
    "<td>$row->formatted_date</td>",
    "<td>"stripslashes($row->headline) ."</td>",
    "<td>"stripslashes($row->season) ."</td>");
    echo 
    implode(PHP_EOL,$out
    or use the HEREDOC method
    Last edited by \\.\; 08-12-2013 at 08:00 AM.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 3 users browsing this thread. (0 members and 3 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles