PHP read/write INI file

Source: Internet
Author: User
Tags read ini file

Read INI file

 Public functionReadini ($name){    if(file_exists(Sem_path. ' init/'.$name)){    $data=Parse_ini_file(Sem_path. ' init/'.$name,true); if($data){            return $data; }    }Else {        return false; }}

Write INI file

functionWrite_ini_file ($assoc _arr,$path,$has _sections=FALSE) {     $content= ""; if($has _sections) {         foreach($assoc _arr  as $key=$elem) {             $content.= "[".$key."] N; foreach($elem  as $key 2=$elem 2) {                 if(Is_array($elem 2))                 {                      for($i= 0;$i<Count($elem 2);$i++)                     {                         $content.=$key 2." [] = "".$elem 2[$i]."" N; }                 }                 Else if($elem 2=="")$content.=$key 2. "= n"; Else $content.=$key 2." = "".$elem 2."" N; }         }     }     Else {         foreach($assoc _arr  as $key=$elem) {             if(Is_array($elem))             {                  for($i= 0;$i<Count($elem);$i++)                 {                     $content.=$key 2." [] = "".$elem[$i]."" N; }             }             Else if($elem=="")$content.=$key 2. "= n"; Else $content.=$key 2." = "".$elem."" N; }     }     if(!$handle=fopen($path, ' W ')) {         return false; }     if(!fwrite($handle,$content)) {         return false; }     fclose($handle); return true; } Usage$sampleData=Array(                ' First ' =Array(                    ' First-1 ' = 1, ' first-2 ' + 2, ' first-3 ' and 3, ' first-4 ' = 4, ' first-5 ' and ' 5,                ), ' second ' =Array(                    ' Second-1 ' = 1, ' second-2 ' + 2, ' second-3 ' and 3, ' Seco Nd-4 ' = 4, ' second-5 ' + 5,)); Write_ini_file ($sampleData, './data.ini ',true);

PHP read/write INI file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.