+ Reply to Thread
Results 1 to 6 of 6

Thread: Small problem with PHP new line character..

  1. #1
    eternalsolitude is offline x10Hosting Member eternalsolitude is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    13

    Post Small problem with PHP new line character..

    I set up an xampp server on my computer to test out script without having to load a remote page every time I update the page. The problem is when I insert "\n" ion my server it will insert a new line, but on x10 it does not. How can I get it to insert a new line if "\n" or "\r" will not work? Thanks in advance.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Small problem with PHP new line character..

    If you would post the code [in code or php brackets] , we might be able to see what the problem is.
    Nothing is always absolutely so.

  3. #3
    eternalsolitude is offline x10Hosting Member eternalsolitude is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    13

    Re: Small problem with PHP new line character..

    Okay, here's an example of where It's giving me a problem
    Code:
    echo "Hello,\n how are you today?"
    I want it to output this:
    "Hello,
    how are you today"

    But instead I get this..
    "Hello,\nhow are you today?"

    Oh. wow, that doesn't accurately show it. I would have to use a <br>.. Well what I'm wanting is a break each line of html echoed from php.
    Last edited by eternalsolitude; 07-24-2011 at 11:06 AM.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Small problem with PHP new line character..

    Are you saying that exact code on x10hosting produces that output?
    Nothing is always absolutely so.

  5. #5
    eternalsolitude is offline x10Hosting Member eternalsolitude is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    13

    Re: Small problem with PHP new line character..

    What I was trying to say is when I put
    Code:
    echo "<html>\n";
    echo "<head>\n";
    I want the actual document to have a line break after the tag <html> and <head>. I was expecting \n to do this, but I was just informed by one of my friends that the php variable "PHP_EOL" is what you use for this.. Sorry for wasting your time.

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Small problem with PHP new line character..

    "\n" should give you a line feed, as long as it's in a double quoted string.

    Try the following exactly as typed:
    PHP Code:
    <?php
    header
    ('Content-type: text/plain');
    echo 
    "Hello,\nhow are you today?";
    ?>
    Do you get a literal '\n' in the output? Or do you just not get a line break when you view the page in a browser? If the latter, it's because HTML treats line breaks the same as any other whitespace outside of <pre> elements and elements with certain values for the CSS white-space property. In HTML, almost all of the time there's a better choice than <br/>; usually, <br> isn't semantic. Instead, you should be using something like <p> or a list (<ul>, <ol> or <dl>).
    Last edited by misson; 07-24-2011 at 01:28 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Finnish character display problem
    By wangsc6686 in forum Free Hosting
    Replies: 0
    Last Post: 03-30-2011, 07:52 AM
  2. Small css problem
    By freecrm in forum Programming Help
    Replies: 2
    Last Post: 01-29-2010, 06:38 AM
  3. Small Problem
    By codsta in forum Free Hosting
    Replies: 2
    Last Post: 01-03-2008, 11:46 AM
  4. Problem with memory on line 80
    By davideb in forum Free Hosting
    Replies: 7
    Last Post: 09-04-2007, 06:32 AM
  5. a small problem
    By ZeptOr in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 12-06-2006, 06:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers