PHP and JS Implementation search tips function code sharing

Source: Internet
Author: User
This paper mainly introduces the real-time search hint function implemented by PHP+JS, which involves the traversal of data and string in real-time with Ajax, and the related operation skill of matching, and the need of friends can be consulted, hoping to help everyone.

As follows:

The code is as follows:

HTML code: (This code is implemented in two ways, a jquery, a native JS)


PHP code is as follows: (PHP can not only consider the use of arrays directly, you can also consider directly querying the database, get the database content, this code uses an array. )


<?php$provinces=array ("Beijing", "Tianjin", "Shanghai", "Chongqing", "Hebei", "Henan", "Heilongjiang", "Jilin", " Changchun ",  " Shandong "," Anhui "," Shanxi "," Guangzhou "," Yunnan "," Hainan "," Xizang "," Qinghai "," Fujian "," Guizhou "," Jiangsu ","  Zhejiang "," Guangzhou "," Yunan "," Hainan "," Xizang "," Neimenggu "," Sichuan "," Gansu "," Ningxia "," Xianggang "," Aomen "); $tmp =$_get[' Q '); $val =array (); $k =0;if (strlen ($tmp) >0) {for  ($i =0; $i <31; $i + +) {    if (Strpos ($provinces [$i], $tmp)!==false) {       //pass value to Val       $val [$k]= $provinces [$i];       Subscript added       $k = $k +1;    }  }  Iterate over the Val array for  ($j =0; $j <count ($val); $j + +)  {    echo $val [$j];    echo "<br>";  }}? >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.