【问题标题】:file_get_contents error in php with codeigniter?使用codeigniter的php中的file_get_contents错误?
【发布时间】:2010-11-24 23:24:28
【问题描述】:

我正在做本教程,但使用了不同的 xml http://blog.insicdesigns.com/2009/03/parsing-xml-file-using-codeigniters-simplexml-library/,但我不断收到相同的错误: 遇到 PHP 错误 严重性:通知 消息:未定义的变量:myxml 文件名:控制器/welcome.php 行号:45

这是我的mi代码:我把xml文件放在目录C:\Users\beto\Documents\xml\myxml.xml,但我想我错了你能帮助我,或者告诉我如何解决它吗?

function _getXML($fname)
  {

      $filename = $fname.’.xml’;
      $xmlfile=“C:\\Users\\beto\\Documents\\xml”.$filename;
      **$xmlRaw = file_get_contents($xmlfile);**ERROR

      $this->load->library(‘simplexml’);
      $xmlData = $this->simplexml->xml_parse($xmlRaw);

      foreach($xmlData[‘Emisor’] as $row)
      {

    $result .= ‘<tr>’;
    $result .= ‘<td>’.$row[‘id’].’</td>’;
    $result .= ‘<td>’.$row[‘name’].’</td>’;
    $result .= ‘<td>’.$row[‘category’].’</td>’;
    $result .= ‘<td>$ ‘.$row[‘price’].’</td>’;
    $result .= ‘</tr>’;

      }
        return $result;
  } 

【问题讨论】:

  • 你应该在那里显示 controllers/welcome.php 和第 45 行
  • 是表示 **$xmlRaw = file_get_contents($xmlfile);**ERROR 的行
  • 您的错误信息与您的源代码不匹配,通知中提到了$myxml,但发布的源中没有$mysql
  • 我更改为 $xmlfile="“C:\Users\beto\Documents\xml\".$filename;,但现在错误显示在 foreach($xmlData['Emisor'] 中$row),我认为前 5 行是一个很大的错误

标签: php xml file-get-contents


【解决方案1】:

缺少\,替换为:

$xmlfile="C:\\Users\\beto\\Documents\\xml\\".$filename;

【讨论】:

  • 我会直接使用 realpath('/Users/beto/Documents/xml/'.$filename); 并忘记所有转义... realpath 应该转换为 Windows 系统路径。
  • 我这样改:$xmlfile=""C:\Users\beto\Documents\xml\".$filename;但现在错误出现在 foreach($xmlData['Emisor'] as $row) what??,我的 xml 的名称是 myxml
  • @GeorgeBecj xml 错误,我想?
  • @prodigitalson 你的意思不是 $xmlfile=""C:\Users\beto\Documents\xml\".$filename;这个 $realpath('/Users/beto/Documents/xml/'.$filename);还是怎么做?
  • 你仍然需要使用驱动器号realpath('C:/Users/beto/Documents/xml/'.$filename); 如果文件不存在,该函数将返回false,所以你应该检查一下。
猜你喜欢
  • 2013-10-25
  • 1970-01-01
  • 1970-01-01
  • 2014-04-26
  • 2015-07-05
  • 1970-01-01
  • 2020-07-05
  • 1970-01-01
  • 2017-09-30
相关资源
最近更新 更多