date()函数
这个函数就比较熟悉了
date()函数
这个函数就比较熟悉了
php写文件的方法
实例一
正则替换掉网页中所有超链接
<?php
$content = file_get_contents('test.html');
$url = 'http://www.phprm.com'; //要换成的新网址
$preg = '/[s]href=("|')[S]*("|')/i';
$replace = ' href="' . $url . '"';
$content = preg_replace($preg, $replace, $content); //正则替换
create_log('newhtml', $content); //生成新文件
?>
php中就是在header一层判断是否是ajax请求,对应的根据$_SERVER['HTTP_X_REQUESTED_WITH']判断。
/**
* 当前请求是否ajax请求
*
* @access public
* @return bool
*/
function isAjax()
{
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'XMLHttpRequest';
}
计算数组平均值 二维数组平均值计算 分组计算平均值
$array = array(
array('class' => 'a', 'value' => 3),
array('class' => 'a', 'value' => 4),
array('class' => 'b', 'value' => 5),
array('class' => 'b', 'value' => 6)
)
【转换原理】:假设IP为:w.x.y.z,则IP地址转为整型数字的计算公式为:intIP = 256*256*256*w + 256*256*x + 256*y + z
【PHP的互转】:PHP的转换方式比较简单,它内置了两个函数
先来看一些
$_SERVER[ 'SERVER_NAME' ] #当前运行脚本所在服务器主机的名称。
$_SERVER[ 'QUERY_STRING' ] #查询(query)的字符串。
$_SERVER[ 'HTTP_HOST' ] #当前请求的 Host: 头部的内容。
$_SERVER[ 'HTTP_REFERER' ] #链接到当前页面的前一页面的 URL 地址。
$_SERVER[ 'SERVER_PORT' ] #服务器所使用的端口
$_SERVER[ 'REQUEST_URI' ] #访问此页面所需的 URI。
功能:对数组进行重新排序.
说明:冒泡排序 (一维数组)(二维数组某个健排序)
实例1
function getFirstCharter($str) {
if (empty($str)) {return '';}
$fchar = ord($str{0});
if ($fchar>=ord('A') && $fchar<=ord('z')) return strtoupper($str{0});
$s1 = iconv('UTF-8', 'gb2312', $str);
$s2 = iconv('gb2312', 'UTF-8', $s1);
$s = $s2 == $str ? $s1 : $str;
$asc = ord($s{0})*256 + ord($s{1}) - 65536;
if ($asc>=-20319 && $asc<=-20284) return 'A';
if ($asc>=-20283 && $asc<=-19776) return 'B';
if ($asc>=-19775 && $asc<=-19219) return 'C';
if ($asc>=-19218 && $asc<=-18711) return 'D';
if ($asc>=-18710 && $asc<=-18527) return 'E';
if ($asc>=-18526 && $asc<=-18240) return 'F';
if ($asc>=-18239 && $asc<=-17923) return 'G';
if ($asc>=-17922 && $asc<=-17418) return 'H';
if ($asc>=-17417 && $asc<=-16475) return 'J';
if ($asc>=-16474 && $asc<=-16213) return 'K';
if ($asc>=-16212 && $asc<=-15641) return 'L';
if ($asc>=-15640 && $asc<=-15166) return 'M';
if ($asc>=-15165 && $asc<=-14923) return 'N';
if ($asc>=-14922 && $asc<=-14915) return 'O';
if ($asc>=-14914 && $asc<=-14631) return 'P';
if ($asc>=-14630 && $asc<=-14150) return 'Q';
if ($asc>=-14149 && $asc<=-14091) return 'R';
if ($asc>=-14090 && $asc<=-13319) return 'S';
if ($asc>=-13318 && $asc<=-12839) return 'T';
if ($asc>=-12838 && $asc<=-12557) return 'W';
if ($asc>=-12556 && $asc<=-11848) return 'X';
if ($asc>=-11847 && $asc<=-11056) return 'Y';
if ($asc>=-11055 && $asc<=-10247) return 'Z';
return null;
}
header()函数
header()函数是PHP中进行页面跳转的一种十分简单的方法。header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。
分卷导入类及思路详解
数据库导入导出是一个后台必要拥有的功能,网上一搜,有很多关于数据库导入导出的,但基本上一个大的系统,包含了许多我们并不需要的,而且他们都是自己的后台的形式,我并不喜欢的是拿人家的东西整合到自己的后台,我需要的是自己东西。于是参照了很多,自己写了一个关于分卷导入类。以方便调用。欢迎大家拍砖。
PHP连接MySQL数据库是通过 mysql_connect() 函数来打开非持久的 MySQL 连接。
语法:
mysql_connect(servername, username, password);
参数说明:
servername:可选。要连接的服务器名称,默认是 "localhost:3306",一般填写 localhost 即可。
username:可选。登录数据库服务器的用户名,一般都是root。
password:可选。登录数据库服务器的密码。