Извлечение значений из URL-адреса xml

Мне нужно распечатать значения внутри тегов Identificador с этого URL-адреса https://clip.unl.pt/sprs?lg=pt&year=2013&uo=97747&srv=rsu&p=1&tp=s&md=3&rs=8145&it=1030123459 , но я не получаю никаких данных на все.

function get_xmlcontent(StdClass $data) { $year = $data->year; $course = $data->clipid; $typeperiod = $data->typeperiod; if ($typeperiod == 's'||$typeperiod == 'a') { $period = $data->period; } else if ($typeperiod == 't') { $period = $data->trimester; } //file from CLIP $xmlUrl = 'https://clip.unl.pt/sprs?lg=pt&year='.$year.'&uo=97747&srv=rsu&p='.$period.'&tp='.$typeperiod.'&md=3&rs='.$course.'&it=1030123459'; $xmlStr = download_file_content($xmlUrl); $xmlObj = simplexml_load_string($xmlStr); foreach ($xmlObj->unidade_curricular->inscritos->aluno as $aluno) { echo $result = $aluno->identificador; } } 

Как я могу это решить?

Вместо вашей пользовательской функции load_file_content () я использовал file_get_contents () и передал xml-строку в SimpleXMLElement. Надеюсь, это указывает на то, что вы в правильном направлении. Рассмотрим разделение функциональности двумя способами: a) buildURL () b) fetchXMLContent ().

 $xmlContent = file_get_contents('https://clip.unl.pt/sprs?lg=pt&year=2013&uo=97747&srv=rsu&p=1&tp=s&md=3&rs=8145&it=1030123459'); $xmlObj = new SimpleXMLElement($xmlContent); foreach($xmlObj->unidade_curricular->inscritos->aluno as $aluno){ $result= $aluno->identificador; echo $result; } 

Чтобы ответить на ваш комментарий: это связано с другой проблемой! Ваши домены – это HTTPS-домен, поэтому вам нужно сообщить cURL, как с этим справиться. Я создал пример, который решает все упомянутые проблемы и демонстрирует использование cURL.

 <?php function buildURL($year, $period, $typeperiod, $course) { return 'https://clip.unl.pt/sprs?lg=pt&year='.$year.'&uo=97747&srv=rsu&p='.$period.'&tp='.$typeperiod.'&md=3&rs='.$course.'&it=1030123459'; } function doRequest_with_FileGetContents($url) { return file_get_contents($url); } function doRequest_with_cURL($url) { $ch=curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); // your domain is a HTTPS domain, so you need to tell curl how to deal with SSL verifications curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $data=curl_exec($ch); curl_close($ch); return $data; } function processXML($xmlContent) { $xmlObj = new SimpleXMLElement($xmlContent); foreach($xmlObj->unidade_curricular->inscritos->aluno as $aluno){ $result= $aluno->identificador; echo $result; } } // Ok. Lets test.. // some testing values, i guess these will come from a formular $year = '2013'; $period = '1'; $typeperiod = 's'; $course = '8145'; // a) build URL $url = buildURL($year, $period, $typeperiod, $course); // b) fetch content $content_a = doRequest_with_cURL($url); $content_b = doRequest_with_FileGetContents($url); // c) process content (should be the same) echo "\nRequest with cURL\n"; processXML($content_a); echo "\nRequest with file_get_contents()\n"; processXML($content_b);