我需要从XML文件中获取图像URL,但由于此URL使用https,因此服务器出现了一些错误。我如何读取https链接并将其关联到http?请帮我,我不懂编程...将HTTPS替换为XML的HTTPS
function api_lastfm($artist, $api_key) {
$data = xml2array(get("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" . urlencode($artist) . "&api_key={$api_key}", false, false, false, 6));
return (isset($data[ 'artist' ][ 'image' ][ 4 ]) && !empty($data[ 'artist' ][ 'image' ][ 4 ])) ? $data[ 'artist' ][ 'image' ][ 4 ] : $data[ 'artist' ][ 'image' ][ 3 ];
}
谢谢!
在转换XML响应(可能只是一个字符串)之前,请使用PHP的[str_replace](http://php.net/manual/en/function.str-replace.php)函数。像:'$ string = str_replace('https:// lastfm-img2','http:// lastfm-img2',$ string)'。但是你确定问题是因为它是一个https网址吗? –
我的服务器日志显示此错误消息:“CURL请求”https://lastfm-img2.akamaized.net/i/u/549d31e77f614f269ca04a6bc156bda2.png“失败!日志:SSL证书问题:无法获取本地颁发者证书”。所以我想将https替换为http。请问,我的代码将如何?我把这个str_replace命令放在哪里?谢谢。 –
我写了一个关于在哪里添加它的答案。这是一个猜测,因为我不知道你的get()方法返回了什么。 –