I'm working with a content management system and a database. My site has a Spanish version, so there's a need to manage a lot of accent characters, as well as the usual items that are best rendered as HTML special characters.

I'm trying to figure out the best way to manage these between my admin site (which uses mostly textareas and a few "<input type='text'>" fields), the public site (which just displays text) and the MySQL database.

Is it better to store accent characters and such in the database as is, or should I translate them to HTML special characters (e.g. "&gt;") before storing them?

I'm thinking if I translate them before storing in the db, they're ready to display in the public site without further translation. On the other hand, if the db doesn't mind storing accent characters, maybe I should store them that way (it's the most "honest" representation of what they are) and just translate them for display.

Any thoughts/opinions?

  • Bob

    my suggestion is to translate them before the database. that way you will know for sure that everything looks the way it is supposed to. if you use those characters weird things might happen when displaying them in a browser.

      Yup - I've arrived at that myself. Translate everything going into the db, using htmlentities. On the read-back, leave everything alone except pairs of "&lt;&gt;" (</>) with stuff in between (bold tags and such) which I'm catching using a regexp. Leave it all raw loading back into the admin site so the </> show up as </>.

        Write a Reply...