I have a <table>
and inside <td>
tags inside it where I am displaying the retrieved data from the backend. Before saving my data to database, I used this to convert \\n
and \\r
into <br />
tags:
$data = nl2br($request->data);
$data = str_replace(array("\r\n", "\n\r", "\r", "\n"), "", $data);
To retrieve data, I tried directly echo-ing the value - ( {{ }}
is echo for Laravel)
<tr>
<td>{{ $item->data }}</td>
</tr>
However, this is displaying <br />
tags on the page instead of turning them into new line breaks.
Then I tried using this approach, which I believe would work, however, this is also displaying the
on the text rather than converting it to new lines.
<tr>
<td>@if ($item){{ str_replace('<br />', ' ', $item->data) }}@endif</td>
</tr>
Also tried replacing br tags to \\n
with using '\\n'
and '\\\\n'
inside str_replace()
but no luck
How can I turn <br />
tags into new lines as usual inside table?
This has nothing to do with the table.
See the documentation :
Blade
{{ }}
statements are automatically sent through PHP'shtmlentities
function to prevent XSS attacks.
and
By default, Blade
{{ }}
statements are automatically sent through PHP'shtmlentities
function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:Hello, {!! $name !!}.
Be very careful when echoing content that is supplied by users of your application. Always use the escaped, double curly brace syntax to prevent XSS attacks when displaying user supplied data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.