php,如何将特殊字符转换为文本?

标签 php wordpress

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 &#038; 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 &#038; 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/

相关文章:

php - Yii2 中的关系和主动查询?

javascript - 从 textarea 获取文本并将其附加到隐藏的输入

php - jQuery 将表单数据发送到 PHP

php - 如何解析 mySql 表的单个字段中的多个值?

php - Facebook、Twitter 等。登录网站不获取电子邮件

php - Symfony 4 - 不渲染 Twig 模板

php - 在 PHP 中利用 MySQL "Comments"部分处理变量,是好还是坏主意?

css - 使垂直的 Wordpress 导航栏子菜单水平

php - MySQL 查询仅适用于 WordPress

php - 可以从谷歌检查器工具复制粘贴并覆盖吗