开发者

Variable content is different upon content-type

开发者 https://www.devze.com 2023-01-10 01:47 出处:网络
Upon transfering my site from one server to another, some functions started behaving differently. The problem lies in building my rss feed. My feed are composed of database posts containing html, and

Upon transfering my site from one server to another, some functions started behaving differently.

The problem lies in building my rss feed. My feed are composed of database posts containing html, and to show them correctly in the feed I then need to change the picture paths to full domain paths, instead of just server root. For this purpose I use simple html dom (http://simplehtmldom.sourceforge.net).

When outputting the varaible html in Content-type: appilication/rss+xml it will show "Object id #1". Should I choose to output it before setting content-type, I get the right html. (in this case < p >test< /p >)

How come I can't output the variable html inside content-type rss+xml?

require_once($_SERVER['DOCUMENT_ROOT'].'/lib/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/functions/simple_html_dom.php');

$html = str_get_html("<p>test</p>");

foreach($html->find('img') as $e) {
    $e->src = $siteconfig['full_domain'].$e->src;       
}

header("Content-Type: application/rss+xml; charset=UTF-8");

$rssfeed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$rssfeed .= "<rss version=\"2.0\">\n";
开发者_运维知识库$rssfeed .= "<channel>\n";
$rssfeed .= "<title>Headline</title>\n";
$rssfeed .= "<language>da</language>\n";
$rssfeed .= "<item>\n\t";
$rssfeed .= "<description><![CDATA[".$html."]]></description>\n\t";
$rssfeed .= "</item>\n";
$rssfeed .= "</channel>\n";
$rssfeed .= "</rss>";

echo $rssfeed;


try this:

$rssfeed .= "<description><![CDATA[".$html->save()."]]></description>\n\t";


Looks really weird. Just try this, for sports: echo $rssfeed." ";

Try also removing everything below header, what's the output then?

0

精彩评论

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