Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Andreas94's avatar

' when saved in the db

in the admin of my site I added the simple dom HTML library to extract data, but i have a big problem.

in the site where I extract the data, there is a sentence with the apostrophe, only that I save it in html entities.

site:

Demone dell'odio

my site:

<td>Demone dell&amp;#039;odio</td>

how do I make the symbol appear and not the entity? because it also saves me in the slug..

this is my code:

      $name_clear = preg_replace('/\s+/', ' ', $value->find('div.trophy-title', 0)->plaintext);

      $trophy->nome = $name_clear;
0 likes
2 replies
bobbybouwmann's avatar

If you wrap the output in htmlspecialchars it should display the correct content for you.

if you're using Laravel and the blade syntax this will be done automatically for you. For example this

{{ $data }}

Will be converted to

<?php echo e($data); ?>

This e helper function in Laravel is doing the htmlspecialchars part for you.

For more info see the code of the helper method: https://github.com/laravel/framework/blob/5.7/src/Illuminate/Support/helpers.php#L550

Andreas94's avatar

@BOBBYBOUWMANN - in my blade I already use {{$value->giochi->nome}} but I still see the symbols.

I tried to do in php:


      $trophy->nome = htmlspecialchars($name_clear);
      $trophy->save();
      $trophy->slug = $trophy->id.'-'.Str::slug($trophy->nome, '-');
      $trophy->save();

but it continues to save me symbols both in the name and in the slug

fixed with

      $trophy->nome = html_entity_decode( $name_clear, ENT_QUOTES );

Please or to participate in this conversation.