开发者

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

I use cURL to get an rss feed from my own wordpress blog to display it as a "feed" sidebar and when I get the headers, all quotes appear as this : ’

The cURL code I use to get that is:

$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);

The strange thing is that in my local server, it brings the quotes ok, but on the remote, it returns this seq.

The code I use to print out the "Feed" follows:

$x = new SimpleXmlElement($content);
    foreach ($x->channel->item as $entry) {
        echo "<li class='newsLI'><a href='$entry->link' title='$entry->title'>" . $en开发者_C百科try->title . "</a></li>";
    }

and what I get, can be clearly seen in the bottom left side of the screen here: http://www.inlinkz.com

Any ideas on where to start looking for an answer?

Thanks in advance!


  1. You don't have a DOCTYPE defined
  2. You aren't setting the page's content-type

Adding the following lines to your code solved your problem (at least on my machine ;)):

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

(of course, this should be set to whatever definition you're actually using)

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


Three lines of code below work for me, and I think they should work globally.

  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';

The very simple trick lies in the variable declaration in the first statement of code, which when called in the second and third (function strip_tags) statements of code shows the rss-feed correctly (in my case) with unicode characters of any length. Note: The value you assign to $settings['rss_strip'] is important. The bigger the value, the more probability of SUCCESS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜