php_eol – PHP Line Breaks : What is PHP_EOL? : PHP_EOL is Broken

php_eol : Use the php constant PHP_EOL to print the correct end of line symbol no matter what system you’re on. It’s used to find the newline character in a cross-platform-compatible.

php_eol – Predefined Constants

php_eol representation of the end of the line. string remove line breaks php Example.

$webInfo = "Welcome To Pakainfo\ndevloped by Angular King\n100% downloading Website";
//OR
$webInfo = "Welcome To Pakainfo" . PHP_EOL . "devloped by Angular King" . PHP_EOL . "100% downloading Website";
echo $webInfo;

Example

 

Results:

Welcome Pakainfo,
I've loved you. 

Using php_eol

$text = 'Line one' . PHP_EOL;
$text .= 'Line two' . PHP_EOL;
 
$file = fopen('file.txt', 'w');
fputs($file, $text);
fclose($file);

using PHP function nl2br()

$webInfo = "Welcome To Pakainfo\ndevloped by Angular King\n100% downloading Website";
//OR
$webInfo = "Welcome To Pakainfo" . PHP_EOL . "devloped by Angular King" . PHP_EOL . "100% downloading Website";
$webInfo = nl2br($webInfo);
echo $webInfo;

Don’t Miss : How To Get The Php_host In PHP?

PHP constant “PHP_EOL”

PHP_EOL is a predefined constant in PHP that represents the end-of-line character sequence for the platform that PHP is running on.

On Windows, the PHP_EOL constant represents the “\r\n” (carriage return + line feed) sequence, while on Unix and Unix-like systems (e.g. macOS, Linux), it represents the “\n” (line feed) character.

You can use PHP_EOL in PHP code to ensure that line breaks are handled correctly on any platform. For example, if you want to write a string to a file with a newline at the end, you could use PHP_EOL to add the appropriate end-of-line sequence:

$file = fopen("example.txt", "w");
fwrite($file, "Hello, world!" . PHP_EOL);
fclose($file);

In this example, we use PHP_EOL to add a newline to the end of the “Hello, world!” string before writing it to the file.

By using PHP_EOL, your code will be more portable across different platforms and will produce consistent line breaks regardless of the environment it is running in.

I hope you get an idea about php_eol.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment