如何从PHP中的远程XML的短语中获取数据?

问题描述 投票:0回答:2

我想从特定节点从远程站点上的XML文件获取数据。但我收到以下错误

警告:PHP行中的simplexml_load_file():

警告2:正在加载文件数据。结果我想获取GRate

注意:我已经在我的PHP安装中启用了SimpleXML模块。


<?php
  $url = "http://api.srinivasajewellery.com/getrate/getrate";
  $xml = simplexml_load_file($url) or die("not open");

  ?><pre><?php //print_r($xml); ?></pre><?php

  foreach($xml->GRate as $GRate){
    printf('$GRate');
  }
?>

我期望在输出中得到“ 3640.00”,但错误如下

警告:simplexml_load_file():http://api.srinivasajewellery.com/getrate/getrate:1:解析器错误:预期开始标记,'

警告:simplexml_load_file():{:GRate“:” 3640.00“,” SRate“:” 49.00“,” PRate“:” 0.00“}在H:\ root \ home \ srinivasauser-001 \ www \ goldrate \ wp中-content \ themes \ twentynineteen \ footer.php,第24行

警告:simplexml_load_file():第24行的H:\ root \ home \ srinivasauser-001 \ www \ goldrate \ wp-content \ themes \ twentynineteen \ footer.php中的^未打开。

我想从特定节点从远程站点上的XML文件获取数据。但是我收到以下错误警告:simplexml_load_file():在php行上出现警告2:它正在加载文件...

php xml simplexml
2个回答
0
投票

尝试以下代码,


0
投票

当使用默认设置从PHP请求URL“ http://api.srinivasajewellery.com/getrate/getrate”时,它将以JSON形式返回数据。在这种情况下,哪个might

© www.soinside.com 2019 - 2024. All rights reserved.