dongyo7931 2012-10-14 10:00
浏览 35
已采纳

使用PHP5读取XML文件[关闭]

So i've been trying to get some data from a PlaystationNetwork API,

http://www.psnapi.com.ar/ps3/api/psn.asmx/getPSNID?sPSNID=jameslfc19

So I've been using this code

<?php
//Get Username
$username = $_GET["u"];

// Passing the XML
$psnxml = @simplexml_load_file('http://psnapi.com.ar/ps3/api/psn.asmx/getPSNID?sPSNID=' .$username);

$psnname = $psnxml->PSNId->Avatar;
echo $psnname;
?>

This outputs absolutely nothing..

I'm using @ because otherwise I get a (Yes i know, but I thought it would still be getting the data even though the XML doc has a 500 Internel Server Error)

Warning: simplexml_load_file(http://psnapi.com.ar/ps3/api/psn.asmx/getPSNID?sPSNID=jameslfc19) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /Applications/XAMPP/xamppfiles/htdocs/Sigs/PSN2.php on line 6

What is the best way to do this? I'm assuming that the error im ignoring with @ is causing the problem.

  • 写回答

1条回答 默认 最新

  • dounuo8797 2012-10-14 10:25
    关注

    In the comments on simlexml_load_file on php.net I found the following. Not tested, but worth a try.

    sean at aliencreations dot com 17-Mar-2011 10:59 If you find that you are receiving 500 errors with simplexml_load_file() but you can access the xml/rss feed manually through a browser, your script is probably being blocked by a user agent sniffer.

    Add this code before your xml call to remedy this issue

    <?php
    
    ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
    ini_set("max_execution_time", 0);
    ini_set("memory_limit", "10000M");
    
    $rss = simplexml_load_file($feed_url);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度