【问题标题】:Laravel line break in messageLaravel 消息中的换行符
【发布时间】:2017-01-13 09:36:55
【问题描述】:

如何在消息中换行。

我试过了

$request->session()->flash('message', "first line \r\n second line");
$request->session()->flash('message', "first line <br> second line");

但他们没有工作,我该如何做到这一点?

【问题讨论】:

标签: php laravel laravel-5.1 message line-breaks


【解决方案1】:

使用&lt;br&gt;,但在显示消息时,使用未转义的回显:

{!! session('message') !!}

https://laravel.com/docs/5.3/blade#displaying-data

【讨论】:

    【解决方案2】:

    你可以试试:

    {!! 'first line <br> second line' !!}
    

    输出

    first line
    second line
    

    {!! nl2br(e('first line <br> second line')) !!}
    

    输出

    first line <br> second line
    

    【讨论】:

      【解决方案3】:

      如果你想使用转义回显,你可以尝试:

      @foreach(explode('<br>', session('message')) as $msg)
      {{ $msg }}
      @if(!$loop->last)
      <br>
      @endif
      @endforeach
      

      【讨论】:

        【解决方案4】:

        像这样在 laravel 中显示未转义的数据。

        {!! $message !!}
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-09-24
          • 2021-09-24
          • 1970-01-01
          • 1970-01-01
          • 2023-04-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多