PHP and AJAX Suggest

 更新时间:2016年11月25日 16:30  点击:1292

PHP and AJAX Suggest

这个suggest是仿google的效果了,google总是走在世界的技术的前面啊,下面我们也来看看实例吧.

先看看html文件.

<form> 
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
下面用js文件的ajax文件来处理数据.
var xmlHttp;

function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  } 
var url="gethint.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
 } 
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
 
这个文件只是返回php处理的数据,而我们的php文件如下.
<?php
// Fill up array with names
$a[]="Anna";
$a[]="Brittany";
$a[]="Cinderella";
$a[]="Diana";
$a[]="Eva";
$a[]="Fiona";
$a[]="Gunda";
$a[]="Hege";
$a[]="Inga";
$a[]="Johanna";
$a[]="Kitty";
$a[]="Linda";
$a[]="Nina";
$a[]="Ophelia";
$a[]="Petunia";
$a[]="Amanda";
$a[]="Raquel";
$a[]="Cindy";
$a[]="Doris";
$a[]="Eve";
$a[]="Evita";
$a[]="Sunniva";
$a[]="Tove";
$a[]="Unni";
$a[]="Violet";
$a[]="Liza";
$a[]="Elizabeth";
$a[]="Ellen";
$a[]="Wenche";
$a[]="Vicky";
//get the q parameter from URL
$q=$_GET["q"];
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
  {
  if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
    {
    if ($hint=="")
      {
      $hint=$a[$i];
      }
    else
      {
      $hint=$hint." , ".$a[$i];
      }
    }
  }
}

//Set output to "no suggestion" if no hint were found
//or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}

//output the response
echo $response;
?>
好了我们的确suggest效果就完成了.
很多朋友想用php或js获取客户端的MAC地址,我可告诉你这是不可能的,除网友权限设置非常底。

class GetMacAddr{   
  
       var $return_array = array(); // 返回带有MAC地址的字串数组   
       var $mac_addr;   
  
       function GetMacAddr($os_type){   
            switch ( strtolower($os_type) ){   
                     case "linux":   
                               $this->forLinux();   
                               break;   
                     case "solaris":   
                               break;   
                     case "unix":   
                               break;   
                     case "aix":   
                               break;   
                     default:   
                               $this->forWindows();   
                               break;   
  
            }   
  
              
            $temp_array = array();   
            foreach ( $this->return_array as $value ){   
  
                      if (   
preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$value,   
$temp_array ) ){   
                               $this->mac_addr = $temp_array[0];   
                               break;   
                     }   
  
            }   
            unset($temp_array);   
            return $this->mac_addr;   
       }   
  
  
       function forWindows(){   
            @exec("ipconfig /all", $this->return_array);   
            if ( $this->return_array )   
                     return $this->return_array;   
            else{   
                     $ipconfig = $_SERVER["WINDIR"]."system32ipconfig.exe";   
                     if ( is_file($ipconfig) )   
                        @exec($ipconfig." /all", $this->return_array);   
                     else  
                        @exec($_SERVER["WINDIR"]."systemipconfig.exe /all", $this->return_array);   
                     return $this->return_array;   
            }   
       }   
  
  
  
       function forLinux(){   
            @exec("ifconfig -a", $this->return_array);   
            return $this->return_array;   
       }   
  
}   
//方法使用   
//$mac = new GetMacAddr(PHP_OS);   
//echo $mac->mac_addr;   

PHP FTP 函数使用教程

引进的PHP的FTP
该功能提供的FTP客户端访问文件服务器通过文件传输协议( FTP ) 。

该FTP函数是用来打开,登录名和密切的联系,以及上传,下载,重命名,删除和获取信息的文件从文件服务器。并不是所有的FTP功能将与每一个服务器或返回同样的结果。该FTP函数成为可与PHP 3 。

这些功能都是为了详细访问FTP服务器。如果你只希望阅读或写入文件在FTP服务器上,可以考虑使用包装的ftp://与文件的功能。 
 

安装
PHP的Windows版本内置了支持的FTP延长。因此, FTP函数将自动工作。

然而,如果您运行的是Linux版本的PHP中,你将不得不与编译PHP -启用-的F TP( P HP4中+ )或- wi th-的F T P(P H P3中)得到的F T P职能工作。 
 

PHP的FTP函数
PHP的:显示最早的PHP版本,支持的功能。
Function Description PHP
ftp_alloc() Allocates space for a file to be uploaded to the FTP server 5
ftp_cdup() Changes the current directory to the parent directory on the FTP server 3
ftp_chdir() Changes the current directory on the FTP server 3
ftp_chmod() Sets permissions on a file via FTP 5
ftp_close() Closes an FTP connection 4
ftp_connect() Opens an FTP connection 3
ftp_delete() Deletes a file on the FTP server 3
ftp_exec() Executes a program/command on the FTP server 4
ftp_fget() Downloads a file from the FTP server and saves it to an open file 3
ftp_fput() Uploads from an open file and saves it to a file on the FTP server 3
ftp_get_option() Returns runtime behaviors of the FTP connection 4
ftp_get() Downloads a file from the FTP server 3
ftp_login() Logs on to an FTP connection 3
ftp_mdtm() Returns the last modified time of a specified file 3
ftp_mkdir() Creates a new directory on the FTP server 3
ftp_nb_continue() Continues retrieving/sending a file (non-blocking) 4
ftp_nb_fget() Downloads a file from the FTP server and saves it to an open file (non-blocking) 4
ftp_nb_fput() Uploads from an open file and saves it to a file on the FTP server (non-blocking) 4
ftp_nb_get() Downloads a file from the FTP server (non-blocking) 4
ftp_nb_put() Uploads a file to the FTP server (non-blocking) 4
ftp_nlist() Lists the files in a specified directory on the FTP server 3
ftp_pasv() Turns passive mode on or off 3
ftp_put() Uploads a file to the FTP server 3
ftp_pwd() Returns the current directory name 3
ftp_quit() Alias of ftp_close() 3
ftp_raw() Sends a raw command to the FTP server 5
ftp_rawlist() Returns a detailed list of files in the specified directory 3
ftp_rename() Renames a file or directory on the FTP server 3
ftp_rmdir() Removes a directory on the FTP server 3
ftp_set_option() Sets runtime options for the FTP connection 4
ftp_site() Sends a SITE command to the server 3
ftp_size() Returns the size of the specified file 3
ftp_ssl_connect() Opens a secure SSL-FTP connection 4
ftp_systype() Returns the system type identifier of the FTP server 3


PHP FTP Constants

PHP: indicates the earliest version of PHP that supports the constant.

Constant Description PHP
FTP_ASCII   3
FTP_TEXT   3
FTP_BINARY   3
FTP_IMAGE   3
FTP_TIMEOUT_SEC   3
FTP_AUTOSEEK   4
FTP_AUTORESUME Determine resume position and start position for get and put requests automatically 4
FTP_FAILED Asynchronous transfer has failed 4
FTP_FINISHED Asynchronous transfer has finished 4
FTP_MOREDATA Asynchronous transfer is still active 4

PHP的zip 使用方法

在Zip文件功能可以让你阅读ZIP文件。


-------------------------------------------------- ------------------------------

安装
对于Zip文件的职能工作,您的服务器,这些图书馆必须安装:

该ZZIPlib库吉Draheim :下载ZZIPlib图书馆
邮编PELC的延伸:下载的Zip PELC延长
安装Linux系统

PHP的5 + :邮政编码职能和邮编图书馆默认情况下不启用的,必须从上面的联系。使用-w ith-拉链=方向配置选项,包括邮政编码的支持。

Windows系统下的安装

PHP的5 + :邮政编码职能默认情况下不启用,所以php_zip.dll和ZZIPlib图书馆必须从上面的连结。 php_zip.dll必须启用内部的php.ini 。

为了使任何PHP扩展, PHP的extension_dir设置(在php.ini文件)应设置的目录下的PHP扩展库的位置。例如extension_dir值是c : PHP的分机。


-------------------------------------------------- ------------------------------

PHP的Zip文件功能
PHP的:显示最早的PHP版本,支持的功能。

Function Description PHP
zip_close() Closes a ZIP file 4
zip_entry_close() Closes an entry in the ZIP file 4
zip_entry_compressedsize() Returns the compressed size of an entry in the ZIP file 4
zip_entry_compressionmethod() Returns the compression method of an entry in the ZIP file 4
zip_entry_filesize() Returns the actual file size of an entry in the ZIP file 4
zip_entry_name() Returns the name of an entry in the ZIP file 4
zip_entry_open() Opens an entry in the ZIP file for reading 4
zip_entry_read() Reads from an open entry in the ZIP file 4
zip_open() Opens a ZIP file 4
zip_read() Reads the next entry in a ZIP file 4

class yl_upload_class
{
#*********************************************************
#创建目录函数
#*********************************************************
function createfolder($yl_path)
{
   if (!file_exists($yl_path))
   {
    $this -> createfolder(dirname($yl_path));
    @mkdir($yl_path, 0777);
   }
   return $this -> createfolder;
}
#*********************************************************
#获取文件名称,大小,类型,临时文件名
#*********************************************************
function yl_getfilename($yl_type)
{
   global $yl_filedata,$yl_directroy,$yl_settingsnew;
   global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
   return $_FILES[$yl_filedata][$yl_type];
}
#*********************************************************
#获取文件大小
#*********************************************************
function yl_getfilesize()
{
   global $yl_filedata,$yl_directroy,$yl_settingsnew;
   global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
   if($this -> yl_getfilename('size') == 0){
      $this -> alert("请选择上传文件!");
      exit;
   }
   if($this -> yl_getfilename('size') > $yl_maxsize){
         $yl_maxsizek=$yl_maxsize/1024;
      $this -> alert("上传文件超出限制范围$yl_maxsizek.K!");
      exit;
   }
   switch (strtolower($yl_sizeformat)){
   case 'b':
   return $this -> yl_getfilename('size') . ' B';
   break;
   case 'k':
   return ($this -> yl_getfilename('size')/1024) . ' K';
   break;
   case 'm':
   return ($this -> yl_getfilename('size'))/(1024*1024) . ' M';
   }
}
#*********************************************************
#获得文件扩展名
#*********************************************************
function yl_getfiletype()
{
   global $yl_filedata,$yl_directroy,$yl_settingsnew;
   global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
     $yl_temp_arr = explode(".", $this -> yl_getfilename('name'));
     $yl_file_ext = array_pop($yl_temp_arr);
      $yl_file_ext = trim($yl_file_ext);
     $yl_file_ext = strtolower($yl_file_ext);
     //检查扩展名
     if (in_array($yl_file_ext, $yl_arrext) === false) {
        $this -> alert("上传文件类型被限制!");
        exit;
     }
     return $yl_file_ext;
}
#*********************************************************
#上传
#*********************************************************
function yl_uploadfile()
{
   global $yl_filedata,$yl_directroy,$file_urldirectroy,$yl_settingsnew;
   global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
   $yl_file_nameold = $this -> yl_getfilename('name');//原文件名
   $yl_file_namenews = date('Ymd').'_'.md5(date('YmdHis'));//重命名
   if($yl_ext == 0){
      $yl_file_names = $yl_file_namenews.'.'.$this -> yl_getfiletype();//改名
   }elseif ($yl_ext == 1){
      $yl_file_names = $yl_file_namenews.'.jpg';//统一改名为jpg
      }
   $yl_tmp_name = $this -> yl_getfilename('tmp_name');//服务器上临时文件名
   $yl_file_size = $this -> yl_getfilesize();//获取文件大小
   $yl_file_type = $this -> yl_getfiletype();//获取文件类型
   $yl_file_path = $yl_directroy.'/'.$yl_settingsnew;//建立一个目录
     //检查目录是否存在,不存在则创建
     if(@is_dir($yl_file_path) === false) {
      $this -> createfolder(''.$yl_file_path.'');//创建目录
     }
     //检查是否已上传
   if(@is_uploaded_file($yl_tmp_name) === false) {
        $this -> alert("文件已上传!");
        exit;
   }
     //检查目录写权限
     if (@is_writable($yl_file_path) === false) {
          $this -> alert("上传目录没有写权限!");
          exit;
     }
   $yl_doupload = @copy($yl_tmp_name, ''.$yl_file_path.'/'.$yl_file_names.'');
   if($yl_doUpload === false)
   {
    $this -> alert("上传失败!");
   }else{
    echo '上传成功';
    echo '<br>';
    echo '文件目录:'.$yl_file_path.'';
    echo '<br>';
    echo '原文件名:'.$yl_file_nameold.'';
    echo '<br>';
    echo '新文件名:'.$yl_file_names.'';
    echo '<br>';
    echo '文件大小:'.$yl_file_size.'';
    echo '<br>';
    echo '文件类型:'.$yl_file_type.'';
   }
    return;
}
#*********************************************************
#*删除文件
#*********************************************************
function delfile()
{
   global $yl_filedata,$yl_directroy,$yl_settingsnew;
   global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
   $yl__dir = dirname(trim($yl_directroy));
   if( $this->_isDel( $yl__dir ) )
   {
      return @unlink( $yl_directroy ) ? true : false;
   }else{
   return false;
   }
}
#*********************************************************
#删除目录 目录下如果有文件不能删除
#*********************************************************
function deldir( )
{
   global $yl_filedata,$yl_directroy,$yl_settingsnew;
   global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
   if( $this->_isdel($yl_directroy) && is_dir( $yl_directroy ) )
   {
      return @rmdir( $yl_directroy ) ? true : false;
   }else{
      return false;
   }
}
#*********************************************************
#提示
#*********************************************************
function alert($yl_msg)
{
    echo '<html>';
    echo '<head>';
    echo '<title>error</title>';
    echo '<meta http-equiv="content-type" c>';
    echo '</head>';
    echo '<body>';
    echo '<script type="text/javascript">alert("'.$yl_msg.'");;</script>';
    echo '</body>';
    echo '</html>';
    exit;
}
}
?>

 

[!--infotagslink--]

相关文章

  • 源码分析系列之json_encode()如何转化一个对象

    这篇文章主要介绍了源码分析系列之json_encode()如何转化一个对象,对json_encode()感兴趣的同学,可以参考下...2021-04-22
  • php中去除文字内容中所有html代码

    PHP去除html、css样式、js格式的方法很多,但发现,它们基本都有一个弊端:空格往往清除不了 经过不断的研究,最终找到了一个理想的去除html包括空格css样式、js 的PHP函数。...2013-08-02
  • index.php怎么打开?如何打开index.php?

    index.php怎么打开?初学者可能不知道如何打开index.php,不会的同学可以参考一下本篇教程 打开编辑:右键->打开方式->经文本方式打开打开运行:首先你要有个支持运行PH...2017-07-06
  • vue.js 表格分页ajax 异步加载数据

    Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20
  • jquery Ajax实现Select动态添加数据

    这篇文章主要为大家详细介绍了jquery Ajax实现Select动态添加数据的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-06-15
  • PHP中func_get_args(),func_get_arg(),func_num_args()的区别

    复制代码 代码如下:<?php function jb51(){ print_r(func_get_args()); echo "<br>"; echo func_get_arg(1); echo "<br>"; echo func_num_args(); } jb51("www","j...2013-10-04
  • PHP编程 SSO详细介绍及简单实例

    这篇文章主要介绍了PHP编程 SSO详细介绍及简单实例的相关资料,这里介绍了三种模式跨子域单点登陆、完全跨单点域登陆、站群共享身份认证,需要的朋友可以参考下...2017-01-25
  • PHP实现创建以太坊钱包转账等功能

    这篇文章主要介绍了PHP实现创建以太坊钱包转账等功能,对以太坊感兴趣的同学,可以参考下...2021-04-20
  • JS基于MSClass和setInterval实现ajax定时采集信息并滚动显示的方法

    这篇文章主要介绍了JS基于MSClass和setInterval实现ajax定时采集信息并滚动显示的方法,涉及JavaScript页面元素定时滚动操作及ajax调用实现技巧,需要的朋友可以参考下...2016-04-19
  • jQuery+ajax简单实现文件上传的方法

    这篇文章主要介绍了jQuery+ajax简单实现文件上传的方法,结合实例形式简单分析了jQuery基于ajax的post方法进行文件传输及asp.net后台处理技巧,需要的朋友可以参考下...2016-06-12
  • php微信公众账号开发之五个坑(二)

    这篇文章主要为大家详细介绍了php微信公众账号开发之五个坑,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-10-02
  • ThinkPHP使用心得分享-ThinkPHP + Ajax 实现2级联动下拉菜单

    首先是数据库的设计。分类表叫cate.我做的是分类数据的二级联动,数据需要的字段有:id,name(中文名),pid(父id). 父id的设置: 若数据没有上一级,则父id为0,若有上级,则父id为上一级的id。数据库有内容后,就可以开始写代码,进...2014-05-31
  • PHP如何通过date() 函数格式化显示时间

    这篇文章主要介绍了PHP如何通过date() 函数格式化显示时间,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-13
  • PHP+jQuery+Ajax实现多图片上传效果

    今天我给大家分享的是在不刷新页面的前提下,使用PHP+jQuery+Ajax实现多图片上传的效果。用户只需要点击选择要上传的图片,然后图片自动上传到服务器上并展示在页面上。...2015-03-15
  • js实现ajax的用户简单登入功能

    这篇文章主要为大家详细介绍了js实现ajax的用户简单登入功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-19
  • golang与php实现计算两个经纬度之间距离的方法

    这篇文章主要介绍了golang与php实现计算两个经纬度之间距离的方法,结合实例形式对比分析了Go语言与php进行经纬度计算的相关数学运算技巧,需要的朋友可以参考下...2016-07-29
  • jQuery UI结合Ajax创建可定制的Web界面

    这篇文章主要为大家详细介绍了jQuery UI结合Ajax创建可定制的Web界面,如何利用Ajax和jQuery UI创建具有各种定制功能的高度可定制的UI,感兴趣的小伙伴们可以参考一下...2016-06-24
  • Repeater事件OnItemCommand取得行内控件的方法

    这篇文章主要介绍了Repeater事件OnItemCommand取得行内控件的方法,有需要的朋友可以参考一下...2021-09-22
  • Bootstrap进度条与AJAX后端数据传递结合使用实例详解

    这篇文章主要介绍了Bootstrap进度条与AJAX后端数据传递结合使用,需要的朋友可以参考下...2017-04-27
  • PHP如何使用cURL实现Get和Post请求

    这篇文章主要介绍了PHP如何使用cURL实现Get和Post请求,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-07-11