Cannot compare with unicode input values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Cannot compare with unicode input values

Post by dibyendrah »

Hello,
I am trying to compare the unicode devangari string with users input. What I did was checking the constant values with user's input. It's not working with unicode input of devanagari but when I compare with english input it's working.

Code: Select all

$input_user = $HTTP_POST_VARS["answer_nepali"];
$check1 = "१२३४५"; //devanagari value for 12345
if($input_user == $check1){
	print "correct answer!";
}
In above script, even though the input is similar to $check1 variable, it's not going inside the if condition.

What may be the problem?

Do I need to change the php configuration file ?

Hoping to get the response soon !

Dibyendra
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Is the encoding of your HTML web page where the user provides input set to UTF-8 ?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

If you have checked everything else....

strcoll
utf8_encode
utf8_decode

as well as checking your locale settings.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

thank you all for your replies. But the Problem is that the unicode value was in &123456#; format so it couldn't t compare with user's input.

cheers,
Dibyendra
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

dibyendrah wrote:thank you all for your replies. But the Problem is that the unicode value was in &123456#; format so it couldn't t compare with user's input.

cheers,
Dibyendra
Do you *need* to have that comparison as entities? html_entity_decode() may help.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

html_entity_decode() might also help but we have to encode user's input to html_entity again. I saved the file as utf8 encoding and it helped me.
Post Reply