Jump to content

Write to specific area of an INI file? HELP!


xZenjix

Recommended Posts

Ok, so I have an INI file...

 

OLD HTML=

NEW HTML=

 

 

I need to write the contents $oldhtml to "OLD HTML=" and the contents of $newhtml to "NEW HTML="

 

To store the contents of an ini file to a variable, I just used

$config = parse_ini_file("config.ini",1);
$email = $config['Email'];
$host = $config['Host'];

 

Cant I just write to the file by selecting ['Old HTML'] and ['NEW HTML'], in a fashion similar to the above code?

From the Documentation:

 

function write_ini_file($assoc_arr, $path, $has_sections=FALSE) {     

$content = "";     

  if ($has_sections) {         
  foreach ($assoc_arr as $key=>$elem) {             
  
   $content .= "[".$key."]\n";              
   
   foreach ($elem as $key2=>$elem2) {                 
    if(is_array($elem2))                  
    {                      
    for($i=0;$i<count($elem2);$i++)                     
     {                          
     $content .= $key2."[] = \"".$elem2[$i]."\"\n";                      
     }                 
      }                 
      else if($elem2=="") $content .= $key2." = \n";                  
      else $content .= $key2." = \"".$elem2."\"\n";              
      }          
      }      
      }      
      else {          
      foreach ($assoc_arr as $key=>$elem) {             
       if(is_array($elem))             
        {                  
        for($i=0;$i<count($elem);$i++)                  
        {                     
         $content .= $key2."[] = \"".$elem[$i]."\"\n";                 
          }             
           }            
             else if($elem=="") $content .= $key2." = \n";              
             else $content .= $key2." = \"".$elem."\"\n";         
              }     
               }      
                if (!$handle = fopen($path, 'w')) {          
                return false;      
                }     
                 if (!fwrite($handle, $content)) {         
                  return false;      
                  }      
                  fclose($handle);      
                  return true;  
                  } 

$sample= array(                 
'first' => array(                    
'first1' => 1,                    
'first2' => 2,                     
'first3' => 3,                    
'first4' => 4             
),                
'second' => array(                    
'second1' => 1,                     
'second2' => 2,                    
'second3' => 3,                     
'second4' => 4
)); 
write_ini_file($sample, 'config.ini', true); 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.