PHP “backspace” character during output possible?

后端 未结 8 1124
囚心锁ツ
囚心锁ツ 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:05

    If the output target is HTML then extra spaces don't matter - browsers don't render multiple, contiguous spaces (which is why we have  )

    If the output target is something else, then you can simply cleanup the output. As you can see from other replies, there are a myriad of ways to do this. It seems like you're working with echo statements so the output-buffering functions will be the route you want to take.

    ob_start();
    
    echo "Hello \n";
    echo "World!";
    
    $output = preg_replace( "/ +/", ' ', str_replace( "\n", ' ', ob_get_clean() ) );
    
    echo $output;
    

提交回复
热议问题