Search code examples
phplaravelutf-8html-entitieshtml-encode

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


Solution

  • 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 -> "