开发者

How to search for a string containing Arabic characters?

开发者 https://www.devze.com 2023-03-14 02:54 出处:网络
I have created a database which stores records, then I have created a search engine th开发者_运维技巧at searches the records

I have created a database which stores records, then I have created a search engine th开发者_运维技巧at searches the records

it works great, except for the Arabic characters, it says "no match found"

that's the search engine code

include('conn.php');
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8'); 

$strlen = strlen($_GET['content']);
$display_count = $_GET['count'];
$select = "SELECT * FROM letter_cast WHERE name LIKE '%".$_GET['content']."%' OR  title LIKE '%".$_GET['content']."%'";
$res = mysql_query($select);
$rec_count = mysql_num_rows($res);

what could be the problem?!


It's most likely that the encoding for the search string is wrong. Make sure you're encoding/decoding it properly with the built-in urlencode/urldecode and utf8_encode/utf8_decode if you need to before passing it on to the SQL query.

How you need do this exactly can depend on your server environment a bit, but in the simplest case it's just:

$content = urldecode($_GET['content']);

You'll also want to make sure the character encoding on any previous page (that links or submits a request to the search page) has been set up correctly or the browser will not encode the request properly.


I know this is a old thread, but it can help other people,

The Php script must also be utf-8 encoded

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号