parsing strings in string.ini using PHP -
i have strings.ini file defining strings like
tz1 = "utc+4:30 asia/kabul" tz2 = "utc+5:45 asia/katmandu" tz3 = "utc-4:30 america/caracas" i have substring value 5:45. based on want lhs part tz2. how using php?
let's say, have settings.ini file. can use parse_ini_file() function this:
settings.ini
[base] tz1 = "utc+4:30 asia/kabul" tz2 = "utc+5:45 asia/katmandu" tz3 = "utc-4:30 america/caracas" php file
// parse without sections $ini_array = parse_ini_file("settings.ini"); print_r($ini_array); this output:
array ( [tz1] => "utc+4:30 asia/kabul" [tz2] => "utc+5:45 asia/katmandu" [tz3] => "utc-4:30 america/caracas" ) now can value of tz2 , value as:
$ini = explode(" ", $ini_array["tz2"]); $ini = str_replace("utc", "", $ini); so, $ini value be: +5:45.
you can loop through both lhs , rhs. :)
Comments
Post a Comment