Adding an enter in php?

Discussion in 'PHP' started by Johnburk, Oct 9, 2007.

  1. #1
    This is probally a real simple question, but I am stuck. I have tried \r\n, and echo "<br/ >" and I am doing something wrong.


    $array_city[$i]['city'] = $row['city']. ' This is your city.';
    Code (markup):
    The above code shows "CITY NAME This is your city.".

    What I would want it to do, is add an enter and then a new line of text. For example:

    CITY NAME This is your city.
    A great city indeed.


    How can I add a new enter in the above code?
     
    Johnburk, Oct 9, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    <br /> makes a new line in the browser, for the user's view. \n makes a new line in the real data (not visible in the browsers normal view).

    Also note that \n needs to be placed between double quotes. It won't be parsed between single quotes.
     
    nico_swd, Oct 9, 2007 IP
  3. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So would that make my code?

    
    $array_city[$i]['city'] = $row['city']. ' This is your city.' '\n' 'A great city indeed;
    Code (markup):
     
    Johnburk, Oct 9, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    No. :)

    And my post above explains why.
     
    nico_swd, Oct 9, 2007 IP
  5. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    $array_city[$i]['city'] = $row['city']. ' This is your city.' "\n" 'A great city indeed;
    Code (markup):
    So it needs to be the above code?
     
    Johnburk, Oct 9, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Almost. You have to place periods between string chunks to avoid parsing errors. (And you could use one single double quote string instead of three different ones)
    
    $array_city[$i]['city'] = $row['city']. " This is your city. \n A great city indeed";
    
    PHP:
     
    nico_swd, Oct 9, 2007 IP
  7. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you. I tried that one, but instead of a new line, I see a square
     
    Johnburk, Oct 9, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    Weird.... try \r\n then.
     
    nico_swd, Oct 9, 2007 IP
  9. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I did, but then I get 2 squares.

    Perhaps its important to mention that the output of the php is displayed in a pdf file.
     
    Johnburk, Oct 9, 2007 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #10
    Yes... post your code.
     
    nico_swd, Oct 9, 2007 IP