如何搜索包含阿拉伯字符的字符串?

时间:2022-09-13 09:32:03

I have created a database which stores records, then I have created a search engine that 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?!

可能是什么问题呢?!

2 个解决方案

#1


3  

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.

搜索字符串的编码很可能是错误的。如果您需要在将其传递给SQL查询之前,请确保使用内置的urlencode / urldecode和utf8_encode / utf8_decode对其进行正确编码/解码。

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.

您还需要确保正确设置任何上一页(将请求链接或提交到搜索页面)的字符编码,否则浏览器将无法正确编码请求。

#2


1  

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

我知道这是一个老线程,但它可以帮助其他人,

The Php script must also be utf-8 encoded

Php脚本也必须是utf-8编码的

#1


3  

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.

搜索字符串的编码很可能是错误的。如果您需要在将其传递给SQL查询之前,请确保使用内置的urlencode / urldecode和utf8_encode / utf8_decode对其进行正确编码/解码。

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.

您还需要确保正确设置任何上一页(将请求链接或提交到搜索页面)的字符编码,否则浏览器将无法正确编码请求。

#2


1  

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

我知道这是一个老线程,但它可以帮助其他人,

The Php script must also be utf-8 encoded

Php脚本也必须是utf-8编码的