首页 > substr

php __call方法使用说明

先说一下__call 的作用吧:"PHP5 对象新增的一个专用方法 ,这个方法用来监视一个对象中的其它方法。如果你试着调用一个对象中不存在的方法,__call 方法将会被自动调用。"

阅读全文

shell 脚本检查某目录下php文件语法


check_php_syntax.sh

#!/bin/bash
# check php syntax
if [ $# -lt 1 ];then
    echo 'Usage: ' $0  'directory';
    exit
fi
if [ ! -d $1 ];then
    echo $1  'not a directory,please check!';
    exit
fi
directory=$1
temp_file="/tmp/file$$"
#echo $temp_file
ls -R $directory | awk  '
    BEGIN{
        FS="n"   
        folder="'$directory'"
        logname="'$temp_file'"
    }
    {
        if($0~/.php$/){
            system("php -l " folder "/" $0  "   >>  " logname  " 2>&1") 
        }
        if($0~/:$/){
            folder=substr($1,1,length($1)-1)
        }
    }
'
if [ -e $temp_file ];then
    cat $temp_file | awk '
        BEGIN{
            error = 0
       }
        {
            if($0~/Parse/) {
                error++
                errorfile[$0] = $0
            }  
        }
        END{
            print "错误文件:" error "个"
            if(length(errorfile)>0) print "错误行数:"
                for (i in errorfile)
                    print i
        }
    '
else
    echo "php file not found."
    exit;
fi

阅读全文

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 curl 分离header和body信息

php中可以通过curl来模拟http请求,同时可以获取http response header和body,当然也设置参数可以只获取其中的某一个。当设置同时获取response header和body时候,它们会一同作为结果返回。这时需要我们自己来分离它们。

阅读全文