I have a web server with a hundred applications developed on PHP 5.2.3, Apache 2.2.4, MySQL 5.0.37 (databases with utf8_general_ci
character set).
I set up a new machine to which I will port the web server that has PHP 5.5.12 (default_charset=UTF-8), Apache 2.4.9 (html head with content="text/html; charset=utf-8"
, MySQL 5.6.17 (test database with utf8_general_ci
character set).
In the PHP scripts I used many time the htmlentities
function in a form like htmlentities($var) (ok not the best way but I was a beginner) in which $var is text extracted from MySQL and contain special chars like "è" (when I save in the dbase I use set var=_utf8'è').
The problem is that on the new server the htmlentities
function returns nothing (the same code in the old server return the correct è
).
After some googling I found a solution that is rewrite the call as htmlentities(utf8_encode($var)), but you know to correct hundred application...
There is a solution (with .ini variables, database charset modification or similar) to maintain the "old" functionality of the htmlentities
function?
[EDIT]
Thanks to CBroe's suggestion, I can solve the problem linked to MySQL using the function mysql_set_charset
called when I connect to the DB (a common function).
But, the problem still remain for a generic conversion. For example, if I want to print the euro symbol and I want to to use the htmlentities
function instead to remember the html code.
As other note if I use htmlentities("è",ENT_QUOTES,'UTF-8') the result is nothing, if I use htmlentities("è",ENT_QUOTES,'ISO-8859-1') or htmlentities("è",ENT_QUOTES,'') the result is right.
PS:
The problem is the same if I pass a string with a special char like "abcdè".
[EDIT] I found a solution for the same problem on the ODBC connection: https://www.saotn.org/php-56-default_charset-change-may-break-html-output/ so setting default_charset = "iso-8859-1" the old applications still work fine.