繁体   English   中英

当使用cURL和php获取rss feed标题时,引号乱码

[英]I get the quotes garbled when getting rss feed titles with cURL and php

我使用cURL从我自己的wordpress博客中获取rss提要,以将其显示为“提要”侧边栏,当我获得标题时,所有引号都显示为:

我用来获取的cURL代码是:

$ch = curl_init($feed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TRANSFERTEXT, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_HEADER, false);
$content = curl_exec($ch);

奇怪的是,在我的本地服务器中,它使报价正常,但是在远程服务器上,它返回此序列。

我用来打印“ Feed”的代码如下:

$x = new SimpleXmlElement($content);
    foreach ($x->channel->item as $entry) {
        echo "<li class='newsLI'><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
    }

在屏幕的左下方可以清楚地看到我所得到的东西: http : //www.inlinkz.com

关于从哪里开始寻找答案的任何想法?

提前致谢!

下面的三行代码对我有用,我认为它们应该在全局范围内工作。

  1. $settings['rss_strip']="1200";

  2. $row['summary'] = $admin->partial($row['summary'],$settings['rss_strip'],0);

  3. $html .= '<description>'. $this->superhtmlentities( strip_tags($row['summary'] ) ).'</description>\\n';

非常简单的技巧在于代码的第一条语句中的变量声明,当在代码的第二条和第三条(函数strip_tags )中调用该变量声明时,可以正确显示rss提要(在我的情况下),并带有任意长度的unicode字符。 注意:您分配给$settings['rss_strip']值很重要。 值越大,成功的可能性越大。

  1. 您没有定义DOCTYPE
  2. 您未设置页面的content-type

将以下行添加到您的代码中解决了您的问题(至少在我的机器上;)):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

(当然,应将其设置为您实际使用的任何定义)

<meta http-equiv="content-type" content="text/html;charset=utf-8" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM