I created a php array file.
My PHP Array File Example.
I put array to g.horje.com/t.php
<?php
$val = array (
0 =>
array (
0 => '1',
'id' => '1',
1 => 'Search Engine Google',
'title' => 'Search Engine Google',
2 => 'Search the world.',
'description' => 'Search the world.',
),
1 =>
array (
0 => '2',
'id' => '2',
1 => 'Social Network',
'title' => 'Social Network',
2 => 'Facebook Social Network',
'description' => 'Facebook Social Network',
),
);
?>
Now I want to get Array Result using url file get contents. Example:
<?php
$homepage = file_get_contents("https://g.horje.com/t.php");
echo $homepage;
foreach($val as $fetch){
echo $fetch['title'];
echo '</br>';
echo $fetch['description'];
}
?>
Can anyone tell me how to execute it ?
echo json_encode($val);as the last line of php code. On the other page, add$val = json_decode($homepage, true);belowecho $homepage;includethe file, which would execute the content and create the$valarray. This isn't a great idea. It represents a possible security hole, and editing the file is prone to error. Go for something like JSON, and usejson_decodeto decide it into an array. It's easier to edit, and doesn't have the risk of executing arbitrary code.