dongqian5384 2014-05-21 08:04
浏览 13
已采纳

PHP外部XML的致命错误

I have a php script which loads an xml file for our shoprating.

<?php
$xml=simplexml_load_file("https://www.kiyoh.nl/xml/recent_company_reviews.xml?xxxxx");

echo "<span itemprop='rating' itemscope itemtype='https://data-vocabulary.org/Rating'>Beoordeling: <span itemprop='average'>";
 foreach($xml->children() as $average)
{
echo $average->total_score;
}
echo "</span>/<span itemprop='best'>10</span></span>";
echo " - <span itemprop='votes'>";
foreach($xml->children() as $total_review)
{
    echo $total_review->total_reviews;
}
echo "</span> stemmen";
?>

Sometimes we get a fatal error on the line

foreach($xml->children() as $average)

I think it has something to do that the xml files can't be accessed. But this script is at the top opf the page, so the rest isn't downloaded anymore.

Is there a way that it can be bypassed? When it can't connect? So the site will be allways visible?

UPDATE 15-08-2014 I use this script to read out my rating at a external site. Sometimes i can't access the external site ... but when that happens my site gives a fatal error.

What should the code be to auto pass this script is not available?

  • 写回答

2条回答 默认 最新

  • douyue6520 2014-08-15 21:52
    关注

    Add

    <?php
    $xml=simplexml_load_file("https://www.kiyoh.nl/xml/recent_company_reviews.xml?xxxxx");
    if (! empty($xml)) {
      //Your code here
    
    } else {
       Echo "There is something wrong getting my xml file. Please try again later";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题