user1759677
user1759677

Reputation: 13

PHP 5.2.17; html_entity_decode - Character decoding issue

So guys im facing a terrible problem that is taking my pacience to solve.

I made a two functions, one to encode data colleted from a wysiwyg editor to send it to a mysql database (the table charset im working with is UTF-8) and other to do the reverse way (Database to wysiwyg), as you can see below.

function displayTextWithTags($textToBeDisplayed) {
    return html_entity_decode(html_entity_decode($textToBeDisplayed));
}

function sendTextToDatabase($text){
    return trim(htmlentities(htmlentities($text, ENT_QUOTES)));
}

It works very well in my development server, which is running a php 5.4.4, but when i upload my application to the my client's server (running php 5.2.7), the decoding does not work properly...

For example, if i send a &\Eacute;&\eacute; (I placed a \ so you can read the code) to the database i'll get a Éé when im retriving it in my development server and a �?é when im retriving it from the client's server.

I've been lurking stack for hours to find an answer for my problem but i did not succeed, so im begging you for help.

Upvotes: 1

Views: 405

Answers (3)

Niels B.
Niels B.

Reputation: 6310

I think we need some clarification here. What do you mean by "retrieving"? I assume you mean 'displayed in browser', so have you first of all checked the character encoding served by your client's webserver by looking in your http headers? It may output as ISO-8859-1.

On a side note, why are you running your entity decoding and encoding twice?

Upvotes: 0

nathan hayfield
nathan hayfield

Reputation: 2685

I had this problem before but I use ADODB database wrapper. For it I had to use this:

 $db->EXECUTE("set names 'utf8'");

Not sure is you are using a database wrapper class but basically you need to set your schema names to utf8. HERE is an example.

Upvotes: 0

The Wavelength
The Wavelength

Reputation: 2924

I'd suggest using base64_encode and base64_decode. That should solve any problems.

Upvotes: 1

Related Questions