xxxi have the_title()
that returns some text, in this case Blue & Whiny
the problem as we can see is that the & character looks different
how do i turn Blue & Whiny
into Blue & Whiny
i tryed: htmlspecialchars_decode(the_title())
, html_entity_decode(the_title())
,htmlspecialchars(the_title())
and nothing.
i want to convert &
to &
there is not much code to share, I just do this: <?php the_title() ?>
and i get Blue & Whiny
. If i use get_the_title()
it wont display anything
Any ideas?
Thanks
edit1. ill share some code:
<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>
I’ve tried everything. This starts to annoy me…
html_entity_decode()
is the correct way to do it.Will produce:
If it’s not working, make sure you don’t have another issue – such as passing a string to it that is double encoded, or running
htmlentities()
on the string again later.Demo: http://codepad.org/BHXGWXJi
Double check with a literal string and
var_dump()
the output, you should see the decoded version. Thenvar_dump(the_title())
, to make sure you are actually passing what you think you are tohtml_entity_decode()
.html_entity_decode should do the trick. If not, try to specify the third parameter
$charset
.Something like:
the_title()
directly prints the title, so addinghtml_entity_decode()
directly around that won’t work. You can, however, stop it from printing with its third function argument. E.g.There’s also
get_the_title()
, which doesn’t directly print the title, but it requires the ID of the post you want the title of, in contrast withthe_title
, which prints the title of the current post in The Loop. So you need to do something like this:And actually, you should be able to simply do:
The only reason these utility functions are there is to escape things for you and add tags and stuff. If you just want the raw input, you can print it directly.
This won’t fix all of your issues, though, because you’re echoing it inside a JavaScript string, so you need to escape certain characters.
json_encode()
should do the trick, but see the question “Pass a PHP string to a Javascript variable (including escaping newlines)” for more details.Try this:
see if this works for ya
http://www.php.net/manual/en/function.mb-decode-numericentity.php