คำอธิบาย
ฟังก์ชัน html_entity_decode() ใช้แปลง HTML entities ทั้งหมดกลับเป็นอักขระเดิม แตกต่างจาก htmlspecialchars_decode() ที่แปลงเฉพาะ 5 entities พื้นฐาน ฟังก์ชันนี้แปลง entities ทุกตัวที่รองรับรวมถึงอักขระอักษรต่างประเทศ
รูปแบบการใช้งาน (Syntax)
html_entity_decode(string $string, int $flags = ENT_COMPAT | ENT_HTML401, string $encoding = "UTF-8"): string
พารามิเตอร์
- string - สตริงที่ต้องการถอดรหัส
- flags - วิธีจัดการเครื่องหมายคำพูด (ENT_COMPAT, ENT_QUOTES, ENT_NOQUOTES)
- encoding - ชุดอักขระ (UTF-8, ISO-8859-1, ฯลฯ)
ค่าที่คืนกลับ (Return Value)
คืนค่าสตริงที่ถอดรหัสแล้ว
ตัวอย่างการใช้งาน
<?php $orig = "We've all the books!"; $one = htmlentities($orig); $two = html_entity_decode($one); echo $one; echo $two; ?>
ผลลัพธ์
We've all the <b>books</b>! We've all the books!