คำอธิบาย
ฟังก์ชัน htmlspecialchars_decode() ใช้แปลง HTML entities กลับเป็นอักขระเดิม เป็นคู่ของ htmlspecialchars() ใช้เมื่อต้องการแสดงข้อมูลที่เคย escape ไว้ กลับสู่รูปแบบเดิม
HTML Entities ที่ถอดรหัสได้
&→&(ampersand)"→"(double quote)'→'(single quote)<→<(less than)>→>(greater than)
รูปแบบการใช้งาน (Syntax)
htmlspecialchars_decode(string $string, int $flags = ENT_COMPAT | ENT_HTML401): string
พารามิเตอร์
- string - สตริงที่ต้องการถอดรหัส
- flags - วิธีจัดการเครื่องหมายคำพูด:
- ENT_COMPAT - ถอดเฉพาะ double quote (ค่าเริ่มต้น)
- ENT_QUOTES - ถอดทั้ง single และ double quote
- ENT_NOQUOTES - ไม่ถอดเครื่องหมายคำพูด
ค่าที่คืนกลับ (Return Value)
คืนค่าสตริงที่ถอดรหัสแล้ว
ตัวอย่างการใช้งาน
<?php $s = "this -> \"keyword in programming language
\n"; echo htmlspecialchars_decode($s); echo htmlspecialchars_decode($s, ENT_NOQUOTES); ?>
ผลลัพธ์
this -> "keyword in programming language
this -> "keyword in programming language