PHP-file_get_contents在Wordpress中不起作用

时间:2018-10-24 07:58:23

标签: php wordpress file-get-contents

我创建了简单的PHP代码。它适用于http://phpfiddle.org/。但这在Wordpress中不起作用。看来第二行在Wordpress中不起作用。知道为什么吗?

PHP代码:

$url = 'https://www.thewebsite.io';
$html = file_get_contents($url);

$html = str_replace("</entry>", "<entry>", $html);
$html = str_replace("<div>]]>", "", $html);
$offers = explode("<entry>", $html);

$ids = explode("id>", $offers[1]);
$id = "nr: ";
$id .= substr($ids[1],9,-5) . "</br>";
echo $id;

$titles = explode("post_title>", $offers[1]);
$title = substr($titles[1],9,-5) . "</br>";
echo $title;

$dates = explode("post_date>", $offers[1]);
$date = "text: ";
$date .= substr($dates[1],9,-5) . "</br>";
echo $date;

$photos = explode("<img", $offers[1]);
$photo = substr(strstr($photos[1], "http"),0,-18) . "</br>";
echo $photo;

谢谢RiggsFolly,我检查了一个https包装器。

$w = stream_get_wrappers();
echo 'openssl: ',  extension_loaded  ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_export($w);

看起来一切正常:

openssl:是 http包装器:是 https包装器:是 包装器:数组(0 =>'https',1 =>'ftps',2 =>'compress.zlib',3 =>'compress.bzip2',4 =>'php',5 =>'文件', 6 =>'glob',7 =>'data',8 =>'http',9 =>'ftp',10 =>'phar',11 =>'zip',)

但是仍然不起作用。看来问题出在Wordpress和file_get_contents之间。知道如何解决这个问题吗?

我解决了这个问题。必须将环境从传统环境切换到稳定环境。

0 个答案:

没有答案