Interview Questions

Why doesn’t the following code print the newline properly? <?php $str = ‘Hello, there.\nHow are you?\nThanks for visiting fyicenter’; print $str; ?>

PHP Interview Questions and Answers


(Continued from previous question...)

Why doesn’t the following code print the newline properly? <?php $str = ‘Hello, there.\nHow are you?\nThanks for visiting fyicenter’; print $str; ?>

Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n.

(Continued on next question...)

Other Interview Questions