How to solve the problem of PHP outputting newline codes as they are

This section describes a problem in PHP where newline codes in strings are output as they are. Normally, when displaying a string containing a newline code (n) in PHP, the newline code is directly output and does not reflect the line break as expected.

To resolve this, you can enclose the newline code in double quotes (“”) to properly reflect the newline.

<?php 
$text = 'aieo' . "n" . 'kakikukeko'; 
? >

In the above example, a newline is inserted between ‘aieo’ and ‘kakikukeko’. Executing this code will insert a line break after the ‘aiueo’ and display ‘kakikukeko’ on the next line.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top