Omzy Posted May 16, 2010 Share Posted May 16, 2010 Just a quick question - should the the ampersand (and other special characters) be stored in it's encoded form (e.g. &) in the database, or should it be stored in its 'raw' form and encoded in the script as and when required? Quote Link to comment Share on other sites More sharing options...
Omzy Posted May 16, 2010 Author Share Posted May 16, 2010 BUMP. Quote Link to comment Share on other sites More sharing options...
Omzy Posted May 17, 2010 Author Share Posted May 17, 2010 Anyone able to help? Quote Link to comment Share on other sites More sharing options...
scampbell Posted May 17, 2010 Share Posted May 17, 2010 Thats entirely up to you although I tend to store it in its raw state as it can be manipulated easier. Then just use htmlentities or whatever to output it to the browser when you need to. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 17, 2010 Share Posted May 17, 2010 I agree with what scampbell stated, always store data in it's raw format, then manipulate the data based upon how you plan to display it. That does NOT mean you should run database queries with unescaped (i.e. unclean data). You should always use mysql_real_escape_string() on all user submitted data (POST, GET, COOKIE, etc.). Then, when you retieve the values determine how the values should be used for display. For example, if you are going to display the values on the HTML page, then you may want to use htmlentities() to prevent the data from wreaking havoc on the display of the page. However, if you are populating a textarea for the user to edit the content you would want to display the data in (mostly) it's raw format and use htmlspecialchars(). Those are only suggestions. You would have to determine what is right for your specific situation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.