making print_r use PHP_EOL

前端 未结 5 863
逝去的感伤
逝去的感伤 2021-01-13 23:42

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 pos

5条回答
  •  攒了一身酷
    2021-01-14 00:24

    Question Is it possible to change the behavior of PHP's print_r function was marked was duplicated of this one . I'd like to answer more how is possible change the behavior of print_r. My propose is do another function with another name that do the print_r customized . And we just need replace print_r functions with print_r_pretty ...

    function print_r_pretty($in, $saveToString = false) {
        $out = print_r($in, true);
        $out = str_replace("\n", "\r\n", $out);
        switch ($saveToString) {
          case true: return $out;
          default: echo $out;
        }
      }
    

    But line :

    $out = str_replace("\n", "\r\n", $out);
    

    can be replaced by another line that do another changes to print_r like this :

    $out = explode("\n", $out, 2)[1];
    

提交回复
热议问题