<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >parse_ini_file</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Filesystem Functions" HREF="ref.filesystem.html"><LINK REL="PREVIOUS" TITLE="move_uploaded_file" HREF="function.move-uploaded-file.html"><LINK REL="NEXT" TITLE="pathinfo" HREF="function.pathinfo.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.move-uploaded-file.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.pathinfo.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.parse-ini-file" ></A >parse_ini_file</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN29308" ></A ><P > (PHP 4 , PHP 5)</P >parse_ini_file -- Parse a configuration file</DIV ><DIV CLASS="refsect1" ><A NAME="AEN29311" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >parse_ini_file</B > ( string filename [, bool process_sections])<BR ></BR ><P > <B CLASS="function" >parse_ini_file()</B > loads in the ini file specified in <VAR CLASS="parameter" >filename</VAR >, and returns the settings in it in an associative array. By setting the last <VAR CLASS="parameter" >process_sections</VAR > parameter to <TT CLASS="constant" ><B >TRUE</B ></TT >, you get a multidimensional array, with the section names and settings included. The default for <VAR CLASS="parameter" >process_sections</VAR > is <TT CLASS="constant" ><B >FALSE</B ></TT > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > This function has nothing to do with the <TT CLASS="filename" >php.ini</TT > file. It is already processed, the time you run your script. This function can be used to read in your own application's configuration files. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > If a value in the ini file contains any non-alphanumeric characters it needs to be enclosed in double-quotes ("). </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > Since PHP 4.2.1 this function is also affected by <A HREF="features.safe-mode.html#ini.safe-mode" >safe mode</A > and <A HREF="features.safe-mode.html#ini.open-basedir" >open_basedir</A >. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > There are reserved words which must not be used as keys for ini files. These include: null, yes, no, true, and false. </P ></BLOCKQUOTE ></DIV ><P > The structure of the ini file is similar to that of the <TT CLASS="filename" >php.ini</TT >'s. </P ><P > <A HREF="language.constants.html" >Constants</A > may also be parsed in the ini file so if you define a constant as an ini value before running <B CLASS="function" >parse_ini_file()</B >, it will be integrated into the results. Only ini values are evaluated. For example: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN29346" ></A ><P ><B >Exemplu 1. Contents of <TT CLASS="filename" >sample.ini</TT ></B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >; This is a sample configuration file ; Comments start with ';', as in php.ini [first_section] one = 1 five = 5 animal = BIRD [second_section] path = /usr/local/bin URL = "http://www.example.com/~username"</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN29351" ></A ><P ><B >Exemplu 2. <B CLASS="function" >parse_ini_file()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />define</font><font color="#007700">(</font><font color="#DD0000">'BIRD'</font><font color="#007700">, </font><font color="#DD0000">'Dodo bird'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Parse without sections<br /></font><font color="#0000BB">$ini_array </font><font color="#007700">= </font><font color="#0000BB">parse_ini_file</font><font color="#007700">(</font><font color="#DD0000">"sample.ini"</font><font color="#007700">);<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$ini_array</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// Parse with sections<br /></font><font color="#0000BB">$ini_array </font><font color="#007700">= </font><font color="#0000BB">parse_ini_file</font><font color="#007700">(</font><font color="#DD0000">"sample.ini"</font><font color="#007700">, </font><font color="#0000BB">true</font><font color="#007700">);<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$ini_array</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > Would produce: </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [one] => 1 [five] => 5 [animal] => Dodo bird [path] => /usr/local/bin [URL] => http://www.example.com/~username ) Array ( [first_section] => Array ( [one] => 1 [five] => 5 [animal] = Dodo bird ) [second_section] => Array ( [path] => /usr/local/bin [URL] => http://www.example.com/~username ) )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.move-uploaded-file.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.pathinfo.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >move_uploaded_file</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.filesystem.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >pathinfo</TD ></TR ></TABLE ></DIV ></BODY ></HTML >