php FILTER_VALIDATE_IP
定义和用法
该过滤器验证FILTER_VALIDATE_IP价值作为一个网址。
名称: “ validate_ip ”
身份证号码: 275
可能的旗帜:
<?php $ip = "192.168.0.1";
if(!filter_var($ip, FILTER_VALIDATE_IP)) { echo "IP is not valid"; } else { echo "IP is valid"; } ?>
输出结果。
is is valid
,下面我们来看看
第一种方法:就是用smary的模板来生成.
require('smarty/Smarty.class.php');
$t = new Smarty;
$t->assign("title","Hello World!");
$content = $t->fetch("templates/index.htm");
//这里的 fetch() 就是获取输出内容的函数,现在$content变量里面,就是要显示的内容了
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
?>
另一种方法是用php od_get_contents来生成
ob_start();
echo "Hello World!";
$content = ob_get_contents();//取得php页面输出的全部内容
$fp = fopen("archives/2005/05/19/0001.html", "w");
fwrite($fp, $content);
fclose($fp);
第三种方法就是用php自然的函数fopen来直接保存.
很多朋友想用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 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 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 |
相关文章
- jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求。该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来编写用户自...2015-10-30
- 系统的学习了一下angularjs,发现angularjs的有些思想根php的模块smarty很像,例如数据绑定,filter。如果对smarty比较熟悉的话,学习angularjs会比较容易一点,这篇文章给大家介绍angularjs filter用法详解,感兴趣的朋友一起学习吧...2015-12-29
MySQL中SELECT+UPDATE处理并发更新问题解决方案分享
问题背景: 假设MySQL数据库有一张会员表vip_member(InnoDB表),结构如下: 当一个会员想续买会员(只能续买1个月、3个月或6个月)时,必须满足以下业务要求: •如果end_at早于当前时间,则设置start_at为当前时间,end_at为当前时...2014-05-31- jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求。该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来编写用户自...2015-10-30
- 这篇文章主要介绍了Mybatis执行update失败的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-09-01
解决Mybatis中mapper.xml文件update,delete及insert返回值问题
这篇文章主要介绍了解决Mybatis中mapper.xml文件update,delete及insert返回值问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-23PowerShell中使用Get-Date获取日期时间并格式化输出的例子
这篇文章主要介绍了PowerShell中使用Get-Date获取日期时间并格式化输出的例子,本文讲解了直接调用Get-Date、在Write-Host中使用Get-Date、格式化输出的方法,需要的朋友可以参考下...2020-06-30nestjs中异常过滤器Exceptionfilter的具体使用
这篇文章主要介绍了nestjs中异常过滤器Exceptionfilter的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-07- 这篇文章主要介绍了jQuery Validate初步体验(二) 的相关资料,需要的朋友可以参考下...2015-12-14
详解git submodule update获取不到最新提交的代码
这篇文章主要介绍了详解git submodule update获取不到最新提交的代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-08-21- 这篇文章主要介绍了PHP如何通过date() 函数格式化显示时间,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-13
使用@JsonFormat和@DateTimeFormat对Date格式化操作
这篇文章主要介绍了使用@JsonFormat和@DateTimeFormat对Date格式化操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-08-10Mysql 原生语句中save or update 的写法汇总
背景  在平常的开发中,经常碰到这种更新数据的场景:先判断某一数据在库表中是否存在,存在则update,不存在则insert。 如果使用Hibernate,它自带saverOrUpdate方法,用起来很方便,但如使用原生sql语句呢?  ...2015-03-15Angularjs中如何使用filterFilter函数过滤
这篇文章主要介绍了Angularjs中如何使用filterFilter函数过滤的相关资料,需要的朋友可以参考下...2016-02-12- 这篇文章主要介绍了mysql update case 更新字段值不固定的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-04
JavaScript下的时间格式处理函数Date.prototype.format
这篇文章主要介绍了JavaScript下的时间格式处理函数Date.prototype.format的相关资料,需要的朋友可以参考下...2016-01-30- 这篇文章主要介绍了jQuery遍历DOM节点操作之filter()方法,结合实例形式详细分析了filter的功能及4种具体用法,需要的朋友可以参考下...2016-04-17
- 这篇文章主要介绍了jquery validate 数组 全部验证问题及解决办法,非常不错,具有参考借鉴价值,需要的朋友参考下吧...2017-01-16
- sql update记录更新详细实例 语法: [ WITH <common_table_expression> [...n] ] UPDATE [ TOP (expression) [ PERCENT ] ] { { table_alias | <object>...2016-11-25
Mysql 数据库死锁过程分析(select for update)
最近有项目需求,需要保证多台机器不拿到相同的数据,后来发现Mysql查询语句使用select.. for update经常导致数据库死锁问题,下面小编给大家介绍mysql 数据库死锁过程分析(select for update),对mysql数据库死锁问题感兴趣的朋友一起学习吧...2015-12-14