php教程常用ip转换与文件下载代码
ip转换
php中将ip转换成整型的函数ip2long()容易出现问题,在ip比较大的情况下,会变成负数。
php教程常用ip转换与文件下载代码
ip转换
php中将ip转换成整型的函数ip2long()容易出现问题,在ip比较大的情况下,会变成负数。
代码二
// date_format2($rs['time'],'%y年%m月%d日%h时%m分%s秒');
function date_format2($string, $format='%b %e, %y', $default_date=null)
{
if (substr(php教程_os,0,3) == 'win') {
$_win_from = array ('%e', '%t', '%d');
$_win_to = array ('%#d', '%h:%m:%s', '%m/%d/%y');
$format = str_replace($_win_from, $_win_to, $format);
}
if($string != '') {
return strftime($format, smarty_make_timestamp($string));
} elseif (isset($default_date) && $default_date != '') {
return strftime($format, smarty_make_timestamp($default_date));
} else {
return;
}
}
function smarty_make_timestamp($string){
if(empty($string)) {
$string = "now";
}
$time = strtotime($string);
if (is_numeric($time) && $time != -1)
return $time;
if (preg_match('/^d{14}$/', $string)) {
$time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
substr($string,4,2),substr($string,6,2),substr($string,0,4));
function getip() {
if(getenv('http_client_ip') && strcasecmp(getenv('http_client_ip'), 'unknown')) {
$onlineip = getenv('http_client_ip');
} elseif(getenv('http_x_forwarded_for') && strcasecmp(getenv('http_x_forwarded_for'), 'unknown')) {
$onlineip = getenv('http_x_forwarded_for');
} elseif(getenv('remote_addr') && strcasecmp(getenv('remote_addr'), 'unknown')) {
$onlineip = getenv('remote_addr');
} elseif(isset($_server['remote_addr']) && $_server['remote_addr'] && strcasecmp($_server['remote_addr'], 'unknown')) {
$onlineip = $_server['remote_addr'];
}
$onlineip = preg_replace("/^([d.]+).*/", "1", $onlineip);
return $onlineip;
}
header() 函数向客户端发送原始的 http 报头。
认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 php教程 4 以及更高的版本中,您可以使用输出缓存来解决此问题):
zend framework invalid command 'rewriteengine'解决办法
zend framework tutorial时候,运行例子,浏览器报错为:
the server encountered an internal error and was unable to complete your request. either the server is overloaded or there was an error in a cgi script.
http_referer ,最简单的图片仿盗就是利用php教程的这个超级全局变量来实例了,但这个函数我们可以很简单的破解,原因我们可以写一个类是于浏览器的相关信息发送。代码如下。
一个很简单的应用实例,就利用了jquery.ajax来实现无刷新登录效果了,方便很简单扼要,实例也只讲了jquery应用这一圬,php教程那款就没讲了,有需要的朋友可以参考一下。
分享一下 我所用的方法。只对php教程myadmin导出的sql文件有效
$dbfile="test.sql";
$content=iconv("utf-8","gb2312",file_get_contents($dbfile));
//获取创建的数据
//去掉注释
$content=preg_replace("/--.*n/iu","",$content);
//替换前缀
$content=str_replace("ct_",table_pre,$content);
sscanf定义和用法及分析
sscanf() 函数根据指定的格式解析来自一个字符串的输入。
如果只向该函数传递两个参数,数据将以数组的形式返回。否则,如果传递了额外的参数,那么被解析的数据会存储在这些参数中。如果区分符的数目大于包含它们的变量的数目,则会发生错误。不过,如果区分符少于变量,则额外的变量包含 null。
php教程 ini_get错误设置方法
利用ini_set可以快速的修改php.ini配置设置哦,无需打开php.ini就可以了,特别是虚拟主机时你没有修改php.ini的权限时就会发现这个函数的作用了,下面看几个实例吧。
*/
//ini_set具有更改php.ini设置的功能。此函数接收两个参数:需要调整的配置变量名,以及变量的新值。
.静态变量
在函数内部static $a = 0;
注意:声明中用表达式的结果对其赋值会导致解析错误如static $a =3+3;(error)
静态变量仅在局部函数域中存在(函数内部),函数执行完之后,变量值不会丢失,可用于递归调用