Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Hàm parse_ini_file() trong PHP


Hàm parse_ini_file() đọc và phân tích file cấu hình INI, trả về mảng liên kết các cài đặt. Tương tự parse_ini_string() nhưng đọc từ file.

Cú pháp

parse_ini_file(file_path, process_sections, scanner_mode)

Tham số

  • file_path – Đường dẫn file INI.

  • process_sections – TRUE: trả về mảng đa chiều theo section. Mặc định FALSE.

  • scanner_mode – INI_SCANNER_NORMAL, INI_SCANNER_RAW, INI_SCANNER_TYPED.

Giá trị trả về

Trả về mảng liên kết cài đặt. FALSE nếu lỗi (file không tồn tại, lỗi cú pháp...).

Ví dụ

File demo.ini:

[names]
one = Anne
two = Katie
three = Tom
[urls]
host1 = "https://www.example1.com"
host2 = "https://www.example2.com"
<?php
print_r(parse_ini_file("demo.ini"));
?>

Kết quả

Array ( [one] => Anne [two] => Katie [three] => Tom [host1] => https://www.example1.com [host2] => https://www.example2.com )