Search code examples
javascriptlaravel-5htmldecode

Can not html entity decode of string in laravel5 blade view


I use Php7.0 and Laravel 5.0 and want to initiate a var in javascript on blade page.

But html_entity_decode function can not decode the special chars.

userName =  "{{ html_entity_decode($user->name) }}"
console.log(userName);

I would like to see " ' < > but it gives me &quot; &#039; &lt; &gt;

While checkin in db I can see correctly.

Any ideas?


Solution

  • I did some quick testing. And the following example works on my side;

    <script type="text/javascript">
        var userName = {!! json_encode($user->name) !!};
        console.log(userName);
    </script>
    

    When I check my console, the userName is displayed properly.