1 Replies - 783 Views - Last Post: 15 November 2013 - 02:39 PM Rate Topic: -----

#1 Keylogger   User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 348
  • Joined: 14-February 11

Special Characters

Posted 15 November 2013 - 11:09 AM


My database currently saves the special characters of a portuguese strings.
Is the following example:
Não necessita de pilhas

Which should be:
Não necessita de pilhas

My problem is not output the value in correct format to screen, but yes passing it by json_encode().
I know that by saying this:

if I echo() the value retrieved from database, the output will be correct, without special characters. But passing it by webservice, to an android app, the special characters stay in the strings.

I'm looking for a function in PHP or maybe an array of possibilities to replace the special characters to the correct characters, already done. Because if there isn't already one function to replace, I'll have to create by myself.

Thank you.

Edit: Solved. I solved the issue on Java side.

This post has been edited by Keylogger: 15 November 2013 - 11:20 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Special Characters

#2 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4241
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Special Characters

Posted 15 November 2013 - 02:39 PM


This is a common consequence of overusing the htmlentities function. Functions like that should not be used before inserting data into the database, for this very reason. It's meant to encode HTML output. Stored data should be neutral, not pre-encoded for a specific output format.

The solution, on PHP's side, would be to remove any calls to that function in your insertion code, and to go through your existing data and run it through the html_entity_decode function, to reset it back to it's neutral form. - Take care, though, to add htmlentities calls to your output code to compensate. Presumably, since your input is being HTML encoded before storage, you don't encode it before outputting it.

A lazier solution would be to add a decode call when sending the data to the Android app only. That would mean you could still keep using the corrupt database code you have now. You'll have to decode all data aimed at any non-HTML output source though! - I'd strongly recommend my first suggestion, if at all possible!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1