Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP – ตรวจจับ HTTP Input Character Encoding ด้วย mb_http_input()

ฟังก์ชัน mb_http_input() ใช้ตรวจจับ character encoding ของ HTTP input รองรับตั้งแต่ PHP 5.4 ขึ้นไป

รูปแบบการใช้งาน (Syntax)

array|string mb_http_input(string $type = null)

พารามิเตอร์

  • $type – ระบุประเภท input ที่ต้องการตรวจสอบ:
    • G – GET
    • P – POST
    • C – COOKIE
    • S – STRING
    • L – LIST
    • I – ทั้งหมด (คืนค่าเป็น array)
    หากละเว้น จะคืนค่า input type ล่าสุดที่ประมวลผล

ค่าที่คืนกลับ

คืนค่าชื่อ character encoding ตาม type ที่ระบุ หรือ array ของ encoding names คืน false หาก type เป็น "I" และไม่มี HTTP input ที่ประมวลผล

ตัวอย่าง

<?php
// คืนค่า input character encoding
$string = mb_http_input("I");
var_dump($string);
?>

ผลลัพธ์

array(1) { [0]=> string(5) "UTF-8" }