Page 1 of 1

Search function error (using mb_convert_encoding)

Posted: Fri Oct 14, 2005 5:12 am
by emmett
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


My mysql is storing data in UTF-8 and have alot of data in Korea and Japan. I used mb_convert_encoding() to convert UTF-8 to EUC-KR(Korea) or Shift-JIS(Japan) to display the webpage. The problem is when I try to query using  EUC-KR(Korea) or Shift-JIS(Japan) as keyword, mostly it will work but sometime didn't. Well I did use the mb_convert_encoding() to convert the EUC-KR(Korea) or Shift-JIS(Japan) back to UTF-8 before I try to query.

Any one know what is the reason?

The keywords I used to search that is not working:
EUC-KR= "디너" or "대쉬" 
Shift-JIS= "ダブ"

Keywords which is working:
EUC-KR= "큐클럽" 
Shift-JIS="ブロック"



Here are the part of the php code:

[index.php]

Code: Select all

<form name="formSearchbyword" action="do_search.php" method="post">
<tr><td align="left">
<input type="text" name="strSearch">
</td>
<td align="right">
<input type="image" src="<?=$imagepath.$_btnSearch?>">
</td></tr>
</form>
[do_search.php]

Code: Select all

function Query($requete) {

$result = mysql_db_query(DB_NAME, $requete);
if (!$this->canNotDie and !$result) { die(mysql_error()); }

if ($this->canNotDie and !$result) {
$this->strSqlError = mysql_error();
$this->intSqlError = mysql_errno();
return false;
}
mysql_free_result($result);
return $array_result;
}

//$strSearch=&#46356;&#45320; over here
$isTranslated= mb_convert_encoding($strSearch, "UTF-8", "EUC-KR");

$sql_query = "SELECT name FROM personal where name like '%$isTranslated%' ";

$res = Query($sql_query);
echo $res["name"];

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Oct 14, 2005 7:50 am
by feyd
why not stay in UTF-8 mode always?

Posted: Sun Oct 16, 2005 8:35 pm
by emmett
Hmm.. that's a very good idea.. but the my webpage will include the header and footer from main website which is using Shift-JIS and EUC-KR.. That's why I need to convert all the UTF-8 to Shift-JIS and EUC-KR.. :-)

Posted: Sun Oct 16, 2005 8:58 pm
by feyd
convert them into UTF-8.. :?