I have a list of cities in a txt file with their respective city name and id, I want to transform it to JSON with a format:
[{"NOMBRE_CIUDAD":"CIUDAD_NOMBRE","ID_CIUDAD":"CIUDAD_ID"}].
What I currently have in the txt is:
"CIUDAD_NOMBRE" "CIUDAD_ID".
Observation: CIUDAD_NOMBRE Y CIUDAD_ID, correspond to some city name and an id.
How could I do this in PHP?
What I have tried is this:
header('Content-Type: application/json');
$json_data = file_get_contents('listadoComunasMarquee.txt');
//json_decode($json_data, true);
echo json_encode($json_data);
But I do not know how to give it the format I require, because it fits like this.
I leave some cities with their respective ID.
OSORNO 104001
COYHAIQUE 114401
PUNTA ARENAS 124901
LAS CONDES 132130
LA PINTANA 132119
RENCA 132108
COLINA 132001
CASTRO 104201