PHP parse_ini_file()ฟังก์ชั่น
❮ การอ้างอิงระบบไฟล์ PHPตัวอย่าง
เนื้อหาของ "test.ini":
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://www.w3schools.com"
รหัส PHP:
<?php
print_r(parse_ini_file("test.ini"));
?>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
Array
(
[me] => Robert
[you] => Peter
[first] => http://www.example.com
[second] => https://www.w3schools.com
)
ความหมายและการใช้งาน
ฟังก์ชัน parse_ini_file() จะวิเคราะห์ไฟล์คอนฟิกูเรชัน (ini) และคืนค่าการตั้งค่า
เคล็ดลับ:ฟังก์ชันนี้สามารถใช้เพื่ออ่านในไฟล์กำหนดค่าของคุณเอง และไม่มีส่วนเกี่ยวข้องกับไฟล์ php.ini
หมายเหตุ:ต้องไม่ใช้คำสงวนต่อไปนี้เป็นคีย์สำหรับไฟล์ ini: null, yes, no, true, false, on, off, none นอกจากนี้ ต้องไม่ใช้อักขระสงวนต่อไปนี้ในคีย์: {}|&~!()^"
ไวยากรณ์
parse_ini_file(file, process_sections, scanner_mode)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
file | Required. Specifies the ini file to parse |
process_sections | Optional. If set to TRUE, it returns is a multidimensional array with section names and settings included. Default is FALSE |
scanner_mode |
Optional. Can be one of the following values:
|
รายละเอียดทางเทคนิค
คืนมูลค่า: | อาร์เรย์ที่ประสบความสำเร็จ FALSE เมื่อล้มเหลว |
---|---|
รุ่น PHP: | 4.0+ |
บันทึกการเปลี่ยนแปลง PHP: | PHP 7.0: ไม่รู้จักเครื่องหมายแฮช (#) เป็นความคิดเห็นอีกต่อไป PHP 5.6.1: เพิ่มโหมด INI_SCANNER_TYPED PHP 5.3: เพิ่มพารามิเตอร์scanner_mode ที่เป็นตัวเลือก |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
เนื้อหาของ "test.ini":
[names]
me = Robert
you = Peter
[urls]
first = "http://www.example.com"
second = "https://www.w3schools.com"
รหัส PHP (โดยตั้งค่า process_sections เป็นจริง):
<?php
print_r(parse_ini_file("test.ini",true));
?>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
Array
(
[names] => Array
(
[me] => Robert
[you] => Peter
)
[urls] => Array
(
[first] => http://www.example.com
[second] => https://www.w3schools.com
)
)
❮ การอ้างอิงระบบไฟล์ PHP