S
S
Svoboo2022-02-15 10:58:22
PHP
Svoboo, 2022-02-15 10:58:22

Why doesn't it output an element from an existing array in php?

There is a code that gets the page response headers:

$ch_head = curl_init();
curl_setopt($ch_head, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch_head, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch_head, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch_head, CURLOPT_TIMEOUT, 30);
curl_setopt($ch_head, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36');
curl_setopt($ch_head,CURLOPT_HEADER, true);
curl_setopt($ch_head, CURLOPT_NOBODY, true);

curl_setopt($ch_head, CURLOPT_URL, 'https://web.archive.org/web/http://d0llmoto.ru/1713562.php');
$headers = curl_exec($ch_head);
curl_close($ch_head);
preg_match('/x-archive-guessed-charset: (.*)/', $headers, $encoding);
print_r($encoding);
echo $encoding[1];

print_r($encoding); displays
Array
(
[0] => x-archive-guessed-charset: windows-1251
[1] => windows-1251
)

echo $encoding[1]; outputs nothing. I don't understand where could be the error? The array is there, the element with index 1 is there, the output should be.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2022-02-15
@Lopar

Everything outputs. Look for the problem on your side.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question