Hello everone my name is reidho i have a problem with my code, i want to mirroring a api output from somesite using file_get_contents but the results is not like the original.

Original Result :
original.png
My Mirroring Result :
result.png
The Code :

$ping = "https://api.hackertarget.com/nping/?q=8.8.8.8";
$pingkeluar   = file($ping);
foreach ($pingkeluar as $pingnya) {
echo " $pingnya ";
}

So I think you have two options:

$file_as_array = file("https://api.hackertarget.com/nping/?q=8.8.8.8");
foreach ($file AS $array AS $line_of_file)
{
    echo "$line_of_file\n"; // \n is used to put a hard return line break at the end of each line
}

Or:

echo file_get_contents("https://api.hackertarget.com/nping/?q=8.8.8.8");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.