PHP Code for Fetching Data from Properties file with KeyElement

PHP Code :

<?php
function FetchDatafromPropertiesFile($Propertyfilename, $Searchkey) {
    $lines = file($Propertyfilename);

    foreach ($lines as $line) {
        list($keyelement, $keyvalue) = explode(':', $line);

        if ($keyelement == $Searchkey) {
            return $keyvalue;
        }
    }

    return false;
}

$Propertyfile = "MyData.Properties";
$Skey = "asd";
$Res = FetchDatafromPropertiesFile($Propertyfile, $Skey);
if (strpos($Res, ',') != False) {
$arraylist = explode(',', $Res);
$max = sizeof($arraylist);
for ($i = 0; $i < $max; $i++) {
echo "<br>".$i." : ".$arraylist[$i];
}
}
else {
echo "Result is : ".$Res;
}
?>

Here in ablove code i have used a "MyData.Properties" file where i have saved some info with some keyvalues and when i need the data i used the Keyvalue to Fetch.

This is only the Raw code you can update it and use it in your Code.

Note : The key value is Case Sensitive.
----------------------------------------
File : MyData.Properties

Asd:Praneeth
Basd:Hyderabad
Csd:Secunderabad
Hsd:mallikarjuna nagar
Isd:Malkajgiri
Qsd:Queen
Rsd:Redrose,PinkRose,OrangeRose,WhiteRose,BlackRose,VoiletRose
Ssd:System
Usd:User
Wsd:Warangal

Comments