PHP “backspace” character during output possible?

后端 未结 8 1263
囚心锁ツ
囚心锁ツ 2021-02-13 04:30

I have a feeling the answer is \"it\'s not possible,\" but thought I\'d ask to satisfy my curiosity.

I have some code that\'s echoed where the \\n is unavoidable:

<
8条回答
  •  被撕碎了的回忆
    2021-02-13 05:17

    If you wanted to be able to do it for anything you could use the output buffer:

    ob_start();
    
    echo "Hello\n World";
    
    $out = ob_get_contents();
    
    ob_end_clear();
    echo str_replace('\n', '', $out);
    

    You could even use httaccess to append scripts containing this to any script called.

    However, couldn't you just deal with it before it is set to stdout? Like

    function print2($str){
        echo str_replace("\n", '', $str);
    }
    

提交回复
热议问题