Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php, how to convert special characters to text?

Tags:

php

wordpress

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

like image 284
Patrioticcow Avatar asked Jul 13 '11 18:07

Patrioticcow


People also ask

What is the use of HTML entities () function in PHP?

htmlentities() Function: The htmlentities() function is an inbuilt function in PHP that is used to transform all characters which are applicable to HTML entities. This function converts all characters that are applicable to HTML entities.

How do I decode HTML entities?

The html_entity_decode() function converts HTML entities to characters. The html_entity_decode() function is the opposite of htmlentities().


1 Answers

html_entity_decode() is the correct way to do it.

html_entity_decode("Blue &#038; Whiny");

Will produce:

Blue & Whiny

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. Then var_dump(the_title()), to make sure you are actually passing what you think you are to html_entity_decode().

like image 54
Wesley Murch Avatar answered Nov 14 '22 19:11

Wesley Murch