code_junkie

Best method for pre and post processing multilingual user input for a php/mysql CMS

Nov 13th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function html_encode($var) {
  2.  
  3. // Encodes HTML safely for UTF-8. Use instead of htmlentities.
  4. $var = htmlentities($var, ENT_QUOTES, 'UTF-8');
  5.  
  6. // convert pesky special characters to unicode
  7. $look = array('™', '™','®','®');
  8. $safe = array('™', '™', '®', '®');
  9.  
  10. $var = str_replace($look, $safe, $var);
  11.  
  12. $var = mysql_real_escape_string($var);
  13.  
  14. return $var;
  15. }
  16.  
  17. function decodeit($var) {
  18.  
  19. return html_entity_decode(stripcslashes($var), ENT_QUOTES, 'UTF-8');
  20. }
  21.  
  22. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  23.  
  24. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Add Comment
Please, Sign In to add comment