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 :
My Mirroring Result :
The Code :

$ping = "https://api.hackertarget.com/nping/?q=";
$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=");
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


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

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