PHP Unicode help needed...

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
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

PHP Unicode help needed...

Post by agriz »

Hi,

I am using Unicode method for Tamil Language. These Tamil words are stored in database like ୱ for 'அ'.

When i execute a query to get the values from database , i am getting zero rows.

SELECT * FROM table_name WHERE name = 'அ' [query is executed like this.]

But the word 'அ' is stored in database like ୱ So before i write query i need to convert the word 'அ' to ୱ

Can anyone tell me how to do this?

Thanks in advance.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Unicode help needed...

Post by Eran »

try utf8_encode() - http://www.php.net/utf8_encode
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: PHP Unicode help needed...

Post by agriz »

Thank you for your reply.

I tired using utf8_encode. But i am getting the same string.

For example, i submit my form after enter a work like 'அ',

i am getting the same work if i pass the word into utf8_encode.

echo $_REQUEST['word'] returns 'அ'
echo utf8_encode($_REQUEST['word']) returns the same 'அ'

any other possibility?

Thanks in advance.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Unicode help needed...

Post by Eran »

The output might look the same, but that's only cause your browser understands UTF-8 encoding. If you var_dump the variable instead, you'll see it has a different length -

Code: Select all

 
var_dump($_REQUEST['word']); 
var_dump(utf8_encode($_REQUEST['word']));
 
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: PHP Unicode help needed...

Post by agriz »

Code: Select all

<html>
<body>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head> 
<?php
if(isset($_REQUEST['submit']))
{
    echo var_dump($_REQUEST['word']);
    echo var_dump(utf8_encode($_REQUEST['word']));
}   
 
?>
<form method="post">
    <input type="text" name="word" />
    <input type="submit" name="submit" />
</form>
</body>
</html>
The input is ... ?

The output is ... (in firefox)
string(7) "?" string(7) "?"

The output is ... (in ie 7)
string(3) "?" string(6) "à®?"

What does it mean?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Unicode help needed...

Post by Eran »

It doesn't make sense to me, especially since I get the same results in all browsers. Did you try putting it in the query and see if it works?
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: PHP Unicode help needed...

Post by agriz »

I am sorry. It is all my mistake.

You are right. Now i got another problem.

In the posting page i used charset iso-8859-1

and in search page i am using charset utf-8 in head tag

while i work with unicode which one is best ?

if utf-8 is best, then how can i migrate my tables?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Unicode help needed...

Post by Eran »

You change the character set / collation. Either through phpmyAdmin or by running the queries directly - http://dev.mysql.com/doc/refman/5.0/en/ ... table.html

Be sure to backup the tables up first.
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: PHP Unicode help needed...

Post by agriz »

okay

I really appreciate your help

Thank you
Post Reply