i have this list on name.txt file :
"name1":"Robert"
"name2":"George"
"name3":"Flophin"
"name4":"Fred"
in a web page i need a php code that takes only the name of the person by the name 1 2 3 4 id.
I've use this in test.php?id=name2
$Text=file_get_contents("./name.txt");
if(isset($_GET["id"])){
$id = $_GET["id"];
$regex = "/".$id."=\'([^\']+)\'/";
preg_match_all($regex,$Text,$Match);
$fid=$Match[1][0];
echo $fid;
} else {
echo "";
}
The result should be George
,
how do i change this to work??
Mabe is another way to do this more simply?