Jump to content

Learning Php question


keeper

Recommended Posts

Hi all, I recently installed IIS 5.1 and PHP 5.2.6 on my Windows XP Pro laptop. I purchased Php 5 for dummies, and followed the install instructions.

I did a simple statement:

 

<?php echo "<p>This is a Php test line</p>"; ?>

 

named the file test.php, and viewed it with my browser by typing in

 

http://localhost/test.php

 

and it works fine. However, if I try to do a statement:

 

<?php echo "This \nis \na \nPhp \ntest \nline</p>"; ?>

 

It just shows the line (This is a Php test line), and does not do a next line using \n

Is this just a problem with my configuration? Using br works, but that's html, not Php right?

 

-Dave

Link to comment
Share on other sites

The \n only affects the display of the source code.

 

If you have firefox, open the page, view the source code behind it and you'll see the words broken up among different lines.

 

\n = new line
\t = tab

 

If you want to show LINE breaks in the html display, use <br>

Link to comment
Share on other sites

Using br works, but that's html, not Php right?

 

PHP is not HTML, but PHP usually produces HTML.  When you use PHP through a webserver and produce an HTML document, you must use HTML tags.  PHP can be used from the command line too, or to produce text documents, CSV, Excel, etc etc, or to produce text inside pre tags and textareas, and that's where \n is useful.

Link to comment
Share on other sites

to create html line breaks you need to do this:

 

<?php

echo "<p>This<br>is<br>a<br>Php<br>test<br>line</p>";

?>

 

otherwise if you use \n; as kratsg said earlier; you will only be creating line breaks in your source code and browsers do not interpret html source code carriage returns as actual html line breaks. .

 

if you view your source code; you will see that this:

 

<?php echo "This \nis \na \nPhp \ntest \nline</p>"; ?>

 

creates this:

 

This

is

a

Php

test

line

 

in your source code.

Link to comment
Share on other sites

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.