1

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 &egrave).

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.

mYmage
  • 92
  • 2
  • 14
  • 1
    PHP functions cannot return void, it can return null – Deep Mar 25 '15 at 14:20
  • If it works when you UTF8-encode the content, but not without that – then you probably neglected to configure that you want to use UTF8 for the database connection or something like that … go work through this: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – CBroe Mar 25 '15 at 14:22
  • @Deep Sorry, I intend that returns nothing. – mYmage Mar 25 '15 at 14:40
  • @CBroe Thanks, mysql_set_charset has solved the problem for data coming from MySQL. I connect with an AS400 DB via ODBC too, and now I cannot try but I think that the problem will persist (view my edit). – mYmage Mar 25 '15 at 15:10
  • @Pepijn van Leeuwen Thanks ;-) – mYmage Mar 25 '15 at 16:19

0 Answers0