-1

我正在尝试使用 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>"; 
  } 
  }

 }     
  }  
4

1 回答 1

0

/^[(a-z) (A-Z) (0-9)]+/u当然不会匹配任何阿拉伯字符。

引用这个答案

preg_match("/\p{Arabic}/u", $string)

当然,提防 SQL 注入并移至PDOmysqli正如已经指出的那样。

于 2013-06-03T15:33:19.783 回答