Move the text to newline

Hi,
I am trying to print the 2nd line of following from a new line. I have tried different options like “\xA” and PHP_EOL but they are not working.

<?php
$dog_error_message = TRUE;
print "variable = $dog_error_message" . $dog_error_message . "\xA" ;
print "variable name =" . '$dog_error_message'. $dog_error_message;
?>

I am getting following output:

variable = 11 variable name =$dog_error_message1

I have tried both ‘echo’ and ‘print’. Somebody please guide me.
I have php 7 installed and my web server is nginix.

Zulfi.

Being inside double quotes, it’s evaluated before PHP outputs it.

Let’s… pump the brakes juuuust a little bit and cover the basics of the question.

You appear to be asking why the text is all on one line.

Web browsers don’t interpret line break characters (\r\n, \n, etc) in their displays.

If you want a line break in the rendered HTML, you need to use the line break tag, "<br>". (or otherwise close a block-level element, but I fear that’s a bit more of an advanced topic for the moment.)

1 Like

If you look at the source of the website (ctrl+u in chrome, or right click on the page, “view source”) you will see the linebreaks there.

An alternative is to indicate to the browser your text is preformatted:

<pre>
<?php
$dog_error_message = TRUE;
print "variable = $dog_error_message" . $dog_error_message . "\xA" ;
print "variable name =" . '$dog_error_message'. $dog_error_message;
?>
</pre>
2 Likes

Hi,
Thanks. It worked.

<pre>
<?php
$dog_error_message = TRUE;
echo "variable = $dog_error_message" . $dog_error_message . "\xA" ;
echo "variable name =" . '$dog_error_message'. $dog_error_message;
?>
</pre>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.