follow us on google+ follow us feedburner


Go to Topic: PreviousNext
Go to: Message ListNew TopicSearchLog InPrint View

problem with htmlspecialchars and non english language

Posted by: SeregaZ
February 13, 2013 10:49AM
i download and instal EasyPHP 5.4.6 (long time ago i have old version and all works fine) and when i am chekcing my old project - i see htmlspecialchars is didnt work properly with another than english languages.

i made some test.php file:
echo htmlspecialchars($_GET['pol']);

when i start this like this:
all work fine, but if in this variable 'pol' present russian letters - this code didnt work:
(%CC it is M, but russian)

but if i put this test.php on some free hosting - all work fine. but i want to make project at home, and than put to this hosting. with didnt work htmlspecialchars i cant to do this. maybe i must to edit some parametres in EasyPHP settings?

Edited 1 time(s). Last edit at 02/13/2013 10:50AM by SeregaZ.
Options: ReplyQuote
Posted by: Russell
February 13, 2013 07:05PM
Using urldecode and declaring the charset, your example works on my server. It also works if you specify the encoding in the htmlentites:

<META http-equiv="content-type" content="text/html; charset=windows-1251">
echo urldecode($_GET['pol']);
<br />
echo htmlspecialchars ( $_GET['pol'] , ENT_COMPAT | ENT_HTML401 , 'cp1251')

I'm guessing your free hosting is Russian and their servers are setup with Russian character encodings (Apache's AddDefaultCharset maybe..? Sorry, I don't know too much about changing the default encoding on Apache.)

Its probably better to use the code above as it should work on any server as you are explicitly telling it what encoding to use rather than relying on the server.
Options: ReplyQuote
Posted by: SeregaZ
February 14, 2013 09:27AM
thanks a lot! :) and yes, my free hosting is russian. but older version of EasyPHP work fine - so i thought i need to some additional set some kind of locale in EasyPHP... but this code is work. thanks.
echo htmlspecialchars ( $_GET['pol'] , ENT_COMPAT | ENT_HTML401 , 'cp1251')
Options: ReplyQuote

Go to: Message ListSearchLog In
Your Name: 
Your Email: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.