TYPO free

home

fighting for TYPO free code

PHP_EOL goodness

16 Feb 2010

I did an amazing discovery today. There is a PHP constant called PHP_EOL you can use instead of "\n". This will make your script cross platform.

I honestly did not know about this. I'm happy I learnt something new today.

<?php

echo "This is an amazing discovery." . PHP_EOL . "I'm so happy! ;-)";

?>

Another great one is DIRECTORY_SEPARATOR.

Find more here: https://php.net/manual/en/reserved.constants.php

Nightfly 18 Feb 2010, 10:04
Don't forget about PATH_SEPARATOR.
I usually define('DS', DIRECTORY_SEPARATOR) and define('PS', PATH_SEPARATOR) for better usability of these constants.
Commenting is closed for this item