我有使用实时AJAX搜索引擎编写的代码,该代码从MySQL数据库中搜索“术语”,其中包含3列ID,标题,描述。
由于某些原因,芬兰语言和波斯/阿拉伯语言字母的特殊字符不可读。 在MySQL数据库中,一切都应该很好,因为放置了排序规则为utf8_general_ci的列以及放置在utf8的索引文件中。
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
字符äöå像���和阿拉伯字符一样显示为????????。 php代码是:
if(isset($_GET['p'])) {
$page_number = $_GET['p'];
$arraySearch = $_GET['terms'];
$show_count = $_GET['count'];
settype($page_number, 'integer');
}
$nospaces = substr ($_GET['terms'],0,4);
$offset = ($page_number - 1) * $records_number;
// check for an empty string and display a message.
if ($_GET['terms'] == "") {
echo '<div id="counter">Kirjoita, että olet homo!</div>';
// minim 3 characters condition
} else if(strlen($_GET['terms']) < $limitchar) {
echo '<div id="counter">'. $limitchar .' characters minimum</div>';
} else {
// explode search words into an array
$arraySearch = explode(" ", $_GET['terms']);
// table fields to search
$arrayFields = array(0 => $first_field, 1 => $second_field);
$countSearch = count($arraySearch);
$a = 0;
$b = 0;
$query = "SELECT * FROM $table_name WHERE (";
$countFields = count($arrayFields);
while ($a < $countFields)
{
while ($b < $countSearch)
{
$query = $query."$arrayFields[$a] LIKE '$arraySearch[$b]%'";
$b++;
if ($b < $countSearch)
{
$query = $query." AND ";
}
}
$b = 0;
$a++;
if ($a < $countFields)
{
$query = $query.") OR (";
}
}
$query = $query.") LIMIT $offset, $records_number;";
$search = mysqli_query($connect, $query);
// get number of search results
$arrayFields = array(0 => $first_field);
$countSearch = count($arraySearch);
$a = 0;
$b = 0;
$query = "SELECT * FROM $table_name WHERE (";
$countFields = count($arrayFields);
while ($a < $countFields)
{
while ($b < $countSearch)
{
$query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'";
$b++;
if ($b < $countSearch)
{
$query = $query." AND ";
}
}
$b = 0;
$a++;
if ($a < $countFields)
{
$query = $query.") OR (";
}
}
$query = $query.")";
$count_results = mysqli_query($connect, $query) or die(mysqli_error($connect));
$numrows = mysqli_num_rows($count_results);
// no results
if($numrows == 0) {
echo '<div id="counter">No results found</div>';
// show results
} else {
echo '<div id="results">
<div id="results_top"><p><b>'. $_GET['terms'] .'</b> - '. $numrows .' results found</p></div>
';
while($row = mysqli_fetch_assoc($search)) {
$title = ($row['title']);
echo '
<div class="item">
<div class="word"><a'.$title.'-'.$row['id'].' class="title">'.$row['title'].'</a></div>
<div class="description" dir="rtl">'.$row['description'].'</div>
<div style="clear:both;"></div></div>';
}
MySQL版本:5.6.36 PHP版本:7.0.23
有什么建议吗? 该代码也已生效,地址为:http://dic.munjutut.fi/php/ 如果键入äiti或aälto,则显示结果。