简体   繁体   中英

Multiline echo PHP not working

I'm new to PHP and I bought this book that told me to download XAMPP and installed it on my laptop. It installed fine but when I started coding, I noticed the multiline echo doesn't work. I tried uninstalling and reinstalling a later version, still it doesn't work. And I tried to install WAMP from another website and still it doesn't work. My code looks like this

<?php
  $author = "Bill Gates";

  $text = "Measuring programming progress by lines of code is like
  Measuring aircraft building progress by weight.

  - $author.";
echo $text;
?>

All I get is this in single line.

Normal people believe that if it ain't broke, don't fix it. Engineers believe that if it ain't broke, it doesn't have enough features yet. - Scott Adams.

I'm using Windows 7. Anybody who has an idea what's wrong, please do reply.

Instead of

echo $text;

use

echo nl2br($text);

See https://secure.php.net/manual/en/function.nl2br.php

Here HTML tag <br /> can help you:

<?php
      $author = "Bill Gates";

      $text = "Measuring programming progress by lines of code is like
      Measuring aircraft building progress by weight.
        <br /><br />
      - $author.";
    echo $text;
    ?>

Here you can see examples: http://www.w3schools.com/tags/tag_br.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM