HTML Entity Decode and Encode | Drupal 8

HTML Entity Decode and Encode

Submitted by editor on Tue, 10/04/2016 - 11:59
Question

How to Encode and decode HTML entitys with drupal 8 ?

Basic php and drupal 7 / 8 Examples

1.
$string_out = html_entity_decode($string, ENT_QUOTES, 'UTF-8')
//Do not forget ENT_QUOTES and 'UTF-8', otherwise quotes will not decodes.

2.
$string_out = check_plain($string)
//Same as : $text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');

3.

Transliterate

$string = "The string to transliterate";
$trans = \Drupal::transliteration();
$string = $trans->transliterate($string, 'en');

 

Add new comment