ฟังก์ชัน html_entity_decode

html_entity_decode แปลง เอนทิตี HTML เป็นอักขระที่ตรงกัน ดูตัวอย่างเพื่อความเข้าใจที่ดีขึ้น

ไวยากรณ์

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

ตัวอย่าง

ลองแปลงสตริงที่มีแท็ก:

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

ผลลัพธ์จากการรันโค้ด:

php'<b>text</b>'

ตัวอย่าง

ลองแปลงสตริงที่มี เครื่องหมายแอมเพอร์แซนด์:

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

ผลลัพธ์จากการรันโค้ด:

php'test: &'

ดูเพิ่มเติม

  • htmlentities,
    ซึ่งทำงานตรงกันข้าม
  • htmlspecialchars,
    ซึ่งทำงานที่คล้ายกันในทางตรงกันข้าม