Я пытаюсь использовать youtube xml для отображения некоторых данных, но появляется эта ошибка.В теории я даже знаю, что не так
$xmlData = simplexml_load_string(utf8_encode(file_get_contents('http://gdata.youtube.com/feeds/api/videos/'.$v.'?fields=title,yt:recorded,yt:statistics'))); //$v is video array
$title = (string)$xmlData->title;
$entry = $xmlData;
$namespaces = $entry->getNameSpaces(true);
$yr = $entry->children((string)$namespaces['yt']);
// get <yt:recorded> node for date and replace yyyy-mm-dd to dd.mm.yyyy
$year = substr($yr->recorded, 0,4);
$month = substr($yr->recorded, 5,2);
$day = substr($yr->recorded, 8,2);
$recorddate = $day.".".$month.".".$year;
// get <yt:stats> node for viewer statistics, and here the problem starts (error appears if view count is 0 / node does not exist)
$attrs = $yr->statistics->attributes();
$viewCount = $attrs[(string)'viewCount'];
{ echo '<p>'.$recorddate.'<br>'.$title.'<br>';
if ($viewCount > 0)
echo $viewCount.'</p></div>';
else
echo '(show some other text)</p></div>'; }
Я знаю, что для решения этой проблемы вы должны сказать php, что узел является строкой, но мне все еще не удалось сделать это, не нарушив остальной код