в строке foreach($decoded->data as $data) происходит ошибка Notice: Undefined property: stdClass::$data in Warning: Invalid argument supplied for foreach() почему это происходит? с другим файлом всё работает хорошо
<?php
function removeBomUtf8($s){
if(substr($s,0,3)==chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF'))){
return substr($s,3);
}else{
return $s;
}
}
$urll = "https://gis-api.aiesec.org/v2/opportunities/757492.json?access_token=e316ebe109dd84ed16734e5161a2d236d0a7e6daf499941f7c110078e3c75493&&with_translations=false";
$content = file_get_contents($urll);
$clean_content = removeBomUtf8($content);
$decoded = json_decode($clean_content);
echo "<table border = 1>";
foreach($decoded->data as $data)
{
$title = (string)$data->title;
$location = (string)$data->location;
$description = (string)$data->description;
echo "<tr>";
echo sprintf(' <td> %s </td><td> %s </td><td> %s </td>', $title, $location, $description);
echo "</tr>";
}
echo '</table>';
?>
Попробуйте так:
<?php
function removeBomUtf8($s){
if(substr($s,0,3)==chr(hexdec('EF')).chr(hexdec('BB')).chr(hexdec('BF'))){
return substr($s,3);
}else{
return $s;
}
}
$urll = "https://gis-api.aiesec.org/v2/opportunities/757492.json?access_token=e316ebe109dd84ed16734e5161a2d236d0a7e6daf499941f7c110078e3c75493&&with_translations=false";
$content = file_get_contents($urll);
$clean_content = removeBomUtf8($content);
$decoded = json_decode($clean_content);
if(isset($decoded->data) && is_array($decoded->data)){
echo "<table border = 1>";
foreach($decoded->data as $data)
{
$title = (string)$data->title;
$location = (string)$data->location;
$description = (string)$data->description;
echo "<tr>";
echo sprintf(' <td> %s </td><td> %s </td><td> %s </td>', $title, $location, $description);
echo "</tr>";
}
echo '</table>';
}else{
$title = (string)$decoded->title;
$location = (string)$decoded->location;
$description = (string)$decoded->description;
echo "<table border = 1>";
echo "<tr>";
echo sprintf(' <td> %s </td><td> %s </td><td> %s </td>', $title, $location, $description);
echo "</tr>";
echo '</table>';
}
?>
И подумайте над тем, чтобы верстку из php выкинуть, по крайней мере, в таком виде (через echo или в переменных).
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости