Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel html_entity_decode using UTF-8

I am using Laravel 4, with PHP and MySQL. Everything is in UTF-8

I have blog titles stored in my database, that look like :

This is an "example" post title

Now on my website, I have images using alt title attributes. When I echo my blog title, I get something like:

<img src="image.jpg" alt="This is an "example" post title" />

Which of course is terrible.

I have tried the following:

{{ html_entity_decode($blog_title, ENT_QUOTES, 'UTF-8') }}

But it doesn't seem to do anything. What am I missing?

I would like the title to display like this: This is an &quot;example&quot; post title

like image 942
pimarc Avatar asked Oct 27 '25 04:10

pimarc


2 Answers

I am using 5.7 laravel version. Below solution solved my problem:

<p>{!! $pa_full_desc !!}</p>

here $pa_full_desc has dummy html content eg.

<p>In lobortis pharetra mattis. Morbi nec nibh iaculis, <a href="#">bibendum augue a</a>, ultrices nulla. Nunc velit ante, lacinia id tincidunt eget, faucibus nec nisl.</p>

This worked for me. Thanks for asking this question.

like image 139
Kamlesh Avatar answered Oct 29 '25 18:10

Kamlesh


Use triple curly quotes:

{{{ $blog_title }}}

The html_entity_decode() does the opposite (and hence leaves " untouched). As a memory hook:

" -> encoding -> &quot;
&quot; -> decoding -> "
like image 24
Boldewyn Avatar answered Oct 29 '25 20:10

Boldewyn