Answer the question
In order to leave comments, you need to log in
How to drive xml server response in php?
Hello, plz tell me how to make the correct header, so all xml tags are cut
$opts = array('http' =>
array(
'header' => "Content-Type: text/plain\r\n"
)
);
$context = stream_context_create($opts);
$str=file_get_contents("https://geocode-maps.yandex.ru/1.x/?geocode=27.525773,53.89079", false, $context);
print_r($str);
Answer the question
In order to leave comments, you need to log in
instead of file_get_contents, this is https://www.php.net/manual/ru/function.simplexml-l...
or drive $str to https://www.php.net/manual/ru/simplexml.examples-b ...
This will give you an object to work with xml.
and a header, depending on how you want to process this file.
function geocode($coords) {
$myCurl = curl_init();
curl_setopt_array($myCurl, array(
CURLOPT_URL => 'https://geocode-maps.yandex.ru/1.x/?geocode='.$coords,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => false,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer 7EG9MK2rWO-puhTKXSBFk_P8LyW1L-K_',
'Content-Type: application/json'
)
));
$response = curl_exec($myCurl);
curl_close($myCurl);
return simplexml_load_string($response);
};
$xml = geocode('27.525773,53.89079');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question