Skip to content
PHP Logo

How does using single quotes versus double quotes affect the interpretation of line breaks in PHP?

Using single quotes in PHP will interpret line breaks as literal characters, while double quotes will interpret line breaks as actual line breaks. To preserve line breaks when using single quotes, you can use the PHP_EOL constant to represent the end of a line.

php
// Using double quotes to interpret line breaks
echo "Line 1\nLine 2\nLine 3";

// Using single quotes with PHP_EOL constant to preserve line breaks
echo 'Line 1' . PHP_EOL . 'Line 2' . PHP_EOL . 'Line 3';