Jump to content

Recommended Posts

Hi, I am trying to learn php from a book and am doing the sample exercises.  I can't figure out why \n isn't making a new line for me.  I am using php 5.2.0.  Here is the code, and it is being output on one line.

 

<?php

$name = "Paul";

print "Your name is $name\n";

$name2 = $name;

$age = 20;

print "Your name is $name2, and your age is $age\n";

print "Goodbye, $name!\n";

?>

 

thanks a lot for your help!

Q.

If you're displaying the output in a browser window then the "\n" has no meaning to the browser and it changes it to a space. To display a newline in a browser window you need to use the "<br>" tag. If you do a "show source" you will see the newlines.

 

Ken

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.