我正在尝试使用php创建搜索引擎从我的数据库搜索阿拉伯语字母,但我没有得到任何东西,但我的代码工作正常与英文字母和数字..... 这是我的代码
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
$name=$_POST['name'];
if(empty($name)) {
echo"Plz enter the Search";
}
if(preg_match("/^[(a-z) (A-Z) (0-9)]+/u", $name)){
//connect to the database
$db=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
//select the database to use
$mydb=mysql_select_db("student");
mysql_set_charset("utf8");
$sql="SELECT id, fname, lname FROM st_information WHERE id LIKE '%" . $name . "%' OR fname LIKE '%" . $name . "%' OR lname LIKE '%" . $name ."%'";
//Run the query against the mysql query function
$result=mysql_query($sql);
//Create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FirstName =$row['fname'];
$LastName=$row['lname'];
$ID=$row['id'];
//Display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"show.php?id=$ID\">" .$FirstName . " " .$LastName . "</a></li>\n";
echo "</ul>";
}
}
}
}
答案 0 :(得分:0)
/^[(a-z) (A-Z) (0-9)]+/u
当然不会与任何阿拉伯语字符匹配。
引用this answer:
preg_match("/\p{Arabic}/u", $string)
当然,请注意SQL注入并转移到已经指出的PDO
或mysqli
。