keeper Posted November 29, 2007 Share Posted November 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/79344-learning-php-question/ Share on other sites More sharing options...
teng84 Posted November 29, 2007 Share Posted November 29, 2007 <?php echo nl2br("This \nis \na \nPhp \ntest \nline</p>"); echo"This \nis \na \nPhp \ntest \nline</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401644 Share on other sites More sharing options...
kratsg Posted November 29, 2007 Share Posted November 29, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401649 Share on other sites More sharing options...
btherl Posted November 29, 2007 Share Posted November 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401659 Share on other sites More sharing options...
phpQuestioner Posted November 29, 2007 Share Posted November 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401661 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 Should probably start using XHTML <br /> Quote Link to comment https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401664 Share on other sites More sharing options...
keeper Posted November 29, 2007 Author Share Posted November 29, 2007 I should have known. I didn't realize the diff from the examples shown in the book, and when I tried it. Got a bit of careful repeat reading to do before I continue... Thanks very much. -Dave Quote Link to comment https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401667 Share on other sites More sharing options...
br3nn4n Posted November 29, 2007 Share Posted November 29, 2007 As teng84 pointed out, using nl2br (a built in PHP function) will take your \n's and make them br's Quote Link to comment https://forums.phpfreaks.com/topic/79344-learning-php-question/#findComment-401814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.