Search code examples
phpeol

making print_r use PHP_EOL


My PHP_EOL is "\r\n", however, when I do print_r on an array each new line has a "\n" - not a "\r\n" - placed after it.

Any idea if it's possible to change this behavior?


Solution

  • Use second param in print_r (set true), read DOC: http://www.php.net/manual/en/function.print-r.php

    See: mixed print_r ( mixed $expression [, bool $return = false ] );

    Example:

    $eol = chr(10); //Break line in like unix
    $weol = chr(13) . $eol; //Break line with "carriage return" (required by some text editors)
    $data = print_r(array(...), true);
    $data = str_replace(eol, weol, $data);
    echo $data;