CKTIS / PHP
PHP_EOL
PHP_EOL is the platform-specific line ending of the PHP runtime: LF on Unix-like systems and CRLF on Windows.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
implode(PHP_EOL, $lines)PHP_EOL is the platform-specific line ending of the PHP runtime: LF on Unix-like systems and CRLF on Windows. Joining records with it inserts separators between records without adding a final separator. A file or network format can specify a different sequence regardless of the host. Preserve explicit CRLF when that format requires it.
$native = implode(PHP_EOL, ["alpha", "beta"]);
$fixed = implode("\r\n", ["alpha", "beta"]);
echo json_encode([
explode(PHP_EOL, $native),
strlen($native) === 9 + strlen(PHP_EOL),
bin2hex(substr($fixed, 5, 2)),
str_ends_with($native, PHP_EOL)
]);
[["alpha","beta"],true,"0d0a",false]
Examples
<?php
$native = implode(PHP_EOL, ["alpha", "beta"]);
$fixed = implode("\r\n", ["alpha", "beta"]);
echo json_encode([
explode(PHP_EOL, $native),
strlen($native) === 9 + strlen(PHP_EOL),
bin2hex(substr($fixed, 5, 2)),
str_ends_with($native, PHP_EOL)
]);
Result
[["alpha","beta"],true,"0d0a",false]