问题
I am trying to solve this problem I am having with my final output.
The XML feed looks like this...
<?xml version='1.0' encoding='utf-8'?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<item> <title>TRON: Legacy, 2010 - ★★★</title>
I would like to preserve the stars in the final output but my final output looks like this...
TRON: Legacy, 2010 - ★★★
Here is the code I am using in PHP -
$title = $item->title;
$movieLink = $item->link;
$xml = new SimpleXMLElement($response);
echo "<div class=\"movies\">";
echo "<a href=\"$movieLink\">$title</a>";
I know this might be an encoding issue of some kind and I've tried converting the string using htmlentities but with no luck. Any help will be greatly appreciated.
回答1:
$title
will be an UTF-8 encoded string in the output. Signal the browser that your website is in UTF-8 and everything is fine:
header("Content-type:text/html; charset=utf-8");
See as well: Setting the HTTP charset parameter
Only Questionmarks what that means? Probably the quick answer is helpful.
来源:https://stackoverflow.com/questions/10859024/what-is-happening-when-simplexml-parses-xml-with-special-characters