Скорее всего, вы хотите отправить эти заголовки ...
header
распечатывает вам заголовки локально, где вы их выполняете.
С file_get_contents
это будет как это:
<?php
$opts = [
"http" => [
"method" => "GET",
"header" => "Content-Type: application/json\r\n" .
"X-RapidAPI-Host: matchilling-chuck-norris-jokes-v1.p.rapidapi.com\r\n" .
"X-RapidAPI-Key: 341b5c1156msh6827bf7184ef4ddp1c8d09jsnbc52db5d01be\r\n"
]
];
$context = stream_context_create($opts);
$str = file_get_contents('https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random', false, $context);
// decode JSON
$json = json_decode($str, true);
// get the data
print_r($json);
Я также любезно предлагаю перейти на расширение curl
.