PHP判断ajax请求类型(HTTP_X_REQUESTED_WITH)


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';
 }

阅读全文

php获取当前页面完整url地址实例

先来看一些

$_SERVER[ 'SERVER_NAME' ] #当前运行脚本所在服务器主机的名称。
$_SERVER[ 'QUERY_STRING' ] #查询(query)的字符串。  
$_SERVER[ 'HTTP_HOST' ] #当前请求的 Host: 头部的内容。  
$_SERVER[ 'HTTP_REFERER' ] #链接到当前页面的前一页面的 URL 地址。  
$_SERVER[ 'SERVER_PORT' ] #服务器所使用的端口  
$_SERVER[ 'REQUEST_URI' ] #访问此页面所需的 URI。  

阅读全文

php获取中文字符拼音首字母实例

实例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;

阅读全文

php mysql备份恢复分卷处理(数据库导入导出)

分卷导入类及思路详解

数据库导入导出是一个后台必要拥有的功能,网上一搜,有很多关于数据库导入导出的,但基本上一个大的系统,包含了许多我们并不需要的,而且他们都是自己的后台的形式,我并不喜欢的是拿人家的东西整合到自己的后台,我需要的是自己东西。于是参照了很多,自己写了一个关于分卷导入类。以方便调用。欢迎大家拍砖。

阅读全文

php连接mysql数据库测试实例详解

PHP连接MySQL数据库是通过 mysql_connect() 函数来打开非持久的 MySQL 连接。 
 语法:
mysql_connect(servername, username, password);
 

参数说明:
servername:可选。要连接的服务器名称,默认是 "localhost:3306",一般填写 localhost 即可。
username:可选。登录数据库服务器的用户名,一般都是root。
password:可选。登录数据库服务器的密码。

阅读全文