horse
horse

Reputation: 725

Paragraph based textarea format in laravel blade?

I have a textarea input from a user like that:

This is first paragraph.
This is second paragraph. The paragraph continues. The end of it.
Third paragraph.

I want to render it like that in laravel blade:

<p>This is first paragraph.</p>
<p>This is second paragraph. The paragraph continues. The end of it.</p>
<p>Third paragraph.</p>

Please note that, I don't want to use breaklines. Beside these, I want to escape each paragraph like that:

<p>e(This is first paragraph.)</p>
<p>e(This is second paragraph. The paragraph continues. The end of it.)</p>
<p>e(Third paragraph.)</p>

How can I perform that?

Upvotes: 1

Views: 4010

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 153070

Just explode the string by the end of line character and then loop through it.

<?php $paragraphs = explode(PHP_EOL, $string); ?>

@foreach($paragraphs as $paragraph)
    <p>{{{ $paragraph }}}</p>
@endforeach

{{{ }}} escape your string like e() would.

Upvotes: 2

Related Questions