xxxi 有 the_title()
返回一些文本,在本例中为 Blue & Whiny
我们看到的问题是 & 字符看起来不一样
我怎么转 Blue & Whiny
进入Blue & Whiny
我试过:htmlspecialchars_decode(the_title())
, html_entity_decode(the_title())
, htmlspecialchars(the_title())
什么都没有。
我想转换 &
至 &
没有太多代码可以分享,我只是这样做:<?php the_title() ?>
我得到 Blue & Whiny
.如果我使用 get_the_title()
它不会显示任何内容
有什么想法吗? 谢谢
编辑1。我分享一些代码:
<script type="text/javascript">
function showShareUI() {
var act = new gigya.services.socialize.UserAction();
act.setUserMessage("Check out this article.");
act.setTitle("Trends on Explore Talent - <?php the_title(); ?>");
act.setDescription("<?php get_the_content(); ?>");
act.setLinkBack("<?php the_permalink(); ?>");
act.addActionLink("Check out this article", "<?php the_permalink(); ?>");
var image = {
src: 'http://xxx.com/wp-content/uploads/2011/05/BOTTOM_BANNER.jpg',
href: '<?php the_permalink();?>',
type: 'image'
}
act.addMediaItem(image);
var params =
{
userAction: act, // The UserAction object enfolding the newsfeed data.
onError: onError, // onError method will be summoned if an error occurs.
onSendDone: onSendDone // onError method will be summoned after
,showEmailButton: true
// Gigya finishes the publishing process.
};
gigya.services.socialize.showShareUI(conf, params);
}
function onError(event) {
alert('An error has occured' + ': ' + event.errorCode + '; ' + event.errorMessage);
}
function onSendDone(event)
{
document.getElementById('status').style.color = "green";
document.getElementById('status').innerHTML = 'The newsfeed has been posted to: ' + event.providers;
}
</script>
我已经尝试了一切。这开始让我烦恼...
最佳答案
html_entity_decode()
是正确的做法。
html_entity_decode("Blue & Whiny");
将产生:
Blue & Whiny
如果它不工作,请确保您没有其他问题 - 例如将一个字符串传递给它是双重编码的,或者运行 htmlentities()
稍后再次在字符串上。
演示:http://codepad.org/BHXGWXJi
用文字字符串和 var_dump()
仔细检查输出,你应该看到解码版本。那么var_dump(the_title())
,以确保您实际上将您认为的传递给了html_entity_decode()
.
关于php,如何将特殊字符转换为文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6683826/