【发布时间】:2017-03-21 09:24:54
【问题描述】:
我已经使用 php 生成了 xml 文件,但问题是我在内容描述中得到 #x2f 十六进制字符代码而不是其符号斜杠 (/)。
Here 是该 xml 文件的 url。你会看到#x2f;描述中的代码。
我正在尝试生成工作的 RSS 提要。
我试过了:
htmlentities(), htmlspecialchars_decode(), html_entity_decode, iconv()
php 字符串函数但不成功。
我也搜索过 Stack 之前的问题,但没有成功。
感谢您的热心帮助。
编辑1(PHP文件代码):
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Hastings Jobs</title>
<description>Latest job vacancies in Hastings and St Leonards, East Sussex</description>
<link>http://hastingsjobs.net</link>
<pubDate>'.gmdate("D, j M Y h:i:s A").'</pubDate>';
$JobQuery = new JobApis\Jobs\Client\Queries\ZiprecruiterQuery([
'api_key' => "APIKEY"
]);
$JobQuery->set('jobs_per_page', '10')->set('location','Hastings, UK')->set('radius_miles','5')->set('days_ago',2);
$client = new JobApis\Jobs\Client\Providers\ZiprecruiterProvider($JobQuery);
$jobs = $client->getJobs();
$i=1;
foreach($jobs->all() as $result)
{
$snippet=str_replace("&", "and", $result->__get('description'));
$jobtitle=str_replace("&", "and", $result->__get('name'));
$date = $result->__get('datePosted');
$date->setTimezone(new DateTimeZone('Europe/London'));
$date->modify('-5 hours');
echo '<item><title>'.$jobtitle.'</title><description>'.htmlentities($snippet, ENT_XML1).'</description><guid>'.htmlEntities($date->format('D, d M Y, H:i:s T')).'</guid><link>'.htmlEntities($result->__get('url')).'</link><pubDate>'.$date->format('D, d M Y, H:i:s T').'</pubDate></item>';
$i=$i+1;
if($i==11) break;
}
echo '</channel>
</rss>';
【问题讨论】:
-
你是如何生成文件的?
-
带标题 - header('Content-Type: text/xml');
-
标头不生成 XML。你说 “我已经使用 PHP 生成了 XML 文件” 我要问的是你是怎么做到的。
-
是的,我正在使用 php 标头创建一个 xml 文件,它告诉编译器将内容编译为 XML。我已将 url 放入以 XML 格式输出的 php 文件中。
-
所以您不是真正生成您从其他地方获取的 XML 的人?除了
header位之外,您使用的完整代码是什么?
标签: php xml string character-encoding html-entities