1

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.

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the suggestion but my boss wants that the data stored in the data base is human readable... So i must find another workaround..
0

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.

1 Comment

Yes, i use a wrapper class with and i use the command that you suggested, but thanks for answering.
0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.