config - how to display context of .cfg file in php? -


i have .cfg file contains code. display whole .cfg in php page. code my_config.cfg here:

# ata/ide/mfm/rll support # account_name=changl # # ide, ata , atapi block devices # config_blk_dev_ide=y config_blk_dev_idedisk=y config_blk_dev_idecd=n 

now wrote php code checks condition , display write in echo. instead of want display file. here php code:

<?php $config_file = "my_config.cfg"; $comment = "#";  $fp = fopen($config_file, "r");  while (!feof($fp)) {   $line = trim(fgets($fp));   if ($line && !preg_match("/^$comment/", $line)) {     $pieces = explode("=", $line);     $option = trim($pieces[0]);     $value = trim($pieces[1]);     $config_values[$option] = $value;   } } fclose($fp);  if ($config_values['account_name'] == "changl")   echo "account_name changl"; else   echo "account_name not changl"; ?> 

the code working properly. want display data in file. please appreciated.

the easiest way use parse_ini_file():

$config_values = parse_ini_file('my_config.cfg'); 

after can work $config_values other regular array


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -