Elegant solution for line-breaks (PHP)

后端 未结 8 2011
太阳男子
太阳男子 2020-12-08 14:28
$var = \"Hi there\".\"
\".\"Welcome to my website\".\"
;\" echo $var;

Is there an elegant way to handle line-breaks in PHP? I\'

8条回答
  •  抹茶落季
    2020-12-08 15:24

    Not very "elegant" and kinda a waste, but if you really care what the code looks like you could make your own fancy flag and then do a str_replace.

    Example:
    $myoutput = "After this sentence there is a line break..|.. Here is a new line.";
    $myoutput = str_replace(".|..","<br />",$myoutput);

    or

    how about:
    $myoutput = "After this sentence there is a line break.E(*)3 Here is a new line.";
    $myoutput = str_replace("E(*)3","<br />",$myoutput);

    I call the first method "middle finger style" and the second "goatse style".

提交回复
热议问题