Mohit Chandel
Mohit Chandel

Reputation: 1916

How to convert string to HTML codes in php laravel?

I have a field in the database which store script tags and I want to implement those script tags into my HTML file but the problem is that data is coming string format

I am trying this

<div class="mb-auto">{{htmlentities($video->ifram)}}</div>

Desired output

<script id="154896_p_269505" width="1280" height="720" src=""  class="dacast-video"></script>

But getting

"&lt;script id=&quot;154896_p_269505&quot; width=&quot;1280&quot; height=&quot;720&quot; src=&quot;https://player.dacast.com/js/player.js?contentId=154896_p_269505&quot; class=&quot;dacast-video&quot;&gt;&lt;/script&gt;"

Upvotes: 1

Views: 1870

Answers (1)

Shizzen83
Shizzen83

Reputation: 3529

You can achieve this by replacing

<div class="mb-auto">{{htmlentities($video->ifram)}}</div>

with

<div class="mb-auto">{!! $video->ifram !!}</div>

But you should be very careful about XSS attack since the JavaScript present in your string will be interpreted by the browser. NEVER do it with a user-provided content!

Upvotes: 2

Related Questions