Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php DOMDocument-加载xml rss-无法打开流_Php_Xml_Domdocument - Fatal编程技术网

Php DOMDocument-加载xml rss-无法打开流

Php DOMDocument-加载xml rss-无法打开流,php,xml,domdocument,Php,Xml,Domdocument,我想从rss url获取链接。这是我的代码: $doc = new DOMDocument(); $doc->load("http://www.alef.ir/rssdx.gmyefy,ggeltshmci.62ay2x.y.xml"); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $title = $node->getElementsByTagName('t

我想从rss url获取链接。这是我的代码:

$doc = new DOMDocument();
$doc->load("http://www.alef.ir/rssdx.gmyefy,ggeltshmci.62ay2x.y.xml");
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {

    $title = $node->getElementsByTagName('title')->item(0)->nodeValue;
    $title=strip_tags($title);
    $link=$node->getElementsByTagName('link')->item(0)->nodeValue;
}
我已将此代码用于其他几个URL,所有URL都有效,但在这一个URL上我得到:

警告:
DOMDocument::load():无法打开流:HTTP请求失败
HTTP/1.1 403第14行的/home/xxxxxxx/domains/xxxxxxx/public_html/data.php中禁止使用
警告:
DOMDocument::load():I/O警告:无法加载外部实体“”
在第14行的/home/xxxxxxx/domains/xxxxxxx/public_html/data.php中

第14行是:

$doc->load("http://www.alef.ir/rssdx.gmyefy,ggeltshmci.62ay2x.y.xml");
你能帮我吗?为什么这个请求会给我一个错误


感谢使用上述代码对我来说失败了,这不是因为我所说的逗号。我发现,使用curl,我能够检索xml文件

$c=curl_init('http://www.alef.ir/rssdx.gmyefy,ggeltshmci.62ay2x.y.xml');
curl_setopt( $c, CURLOPT_USERAGENT,'nginx-curl-blahblahblah' );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, true );
$r=curl_exec( $c );
curl_close( $c );

$doc = new DOMDocument();
$doc->loadxml($r);
$arrFeeds = array();

foreach ($doc->getElementsByTagName('item') as $node) {

    $title=$node->getElementsByTagName('title')->item(0)->nodeValue;
    $title=strip_tags($title);
    $link=$node->getElementsByTagName('link')->item(0)->nodeValue;

}

在调用提要之前添加此代码,这将更改用户代理

$opts = array(
    'http' => array(
        'user_agent' => 'PHP libxml agent',
    )
);

$context = stream_context_create($opts);
libxml_set_streams_context($context);

URL中有一个逗号-也许这是抛出错误的原因?非常感谢您添加此答案。我在试图用一点第三方代码来解决这个问题时失去了理智,这就是它!