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
https://forums.phpfreaks.com/topic/79344-learning-php-question/
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
https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401659
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
https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401661
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.