The html_entity_decode Function

The html_entity_decode function converts HTML entities to their corresponding characters. See examples for better understanding.

Syntax

phphtml_entity_decode(string $string, int $flags = ENT_COMPAT, ?string $encoding = null): string

Example

Let's convert a string with tags:

php<?php
  $str = '<b>text</b>';
  $res = html_entity_decode($str);
  
  echo $res;
?>

Code execution result:

php'<b>text</b>'

Example

Let's convert a string with an ampersand:

php<?php
  $str = 'test: &';
  $res = html_entity_decode($str);
  
  echo $res;
?>

Code execution result:

php'test: &'

See Also