2015年11月

PHP 5.3.1 安装包 VC9 VC6 区别是什么

一、如何选择PHP5.3的VC9版本和VC6版本
VC6是什么?
VC6就是legacy Visual Studio 6 compiler,就是使用这个编译器编译的。
VC9是什么?
VC9就是the Visual Studio 2008 compiler,就是用微软的VS编辑器编译的。
那我们如何选择下载哪个版本的PHP呢?
如果你是在windows下使用Apache+PHP的,请选择VC6版本;
如果你是在windows下使用IIS+PHP的,请选择VC9版本。

二、如何选择PHP5.3的Thread Safe和Non Thread Safe版本

先从字面意思上理解,Thread Safe是线程安全,执行时会进行线程(Thread)安全检查,以防止有新要求就启动新线程的CGI执行方式而耗尽系统资源。Non Thread Safe是非线程安全,在执行时不进行线程(Thread)安全检查。

再来看PHP的两种执行方式:ISAPI和FastCGI。

ISAPI执行方式是以DLL动态库的形式使用,可以在被用户请求后执行,在处理完一个用户请求后不会马上消失,所以需要进行线程安全检查,这样来提高程序的执行效率,所以如果是以ISAPI来执行PHP,建议选择Thread Safe版本;

而FastCGI执行方式是以单一线程来执行操作,所以不需要进行线程的安全检查,除去线程安全检查的防护反而可以提高执行效率,所以,如果是以FastCGI来执行PHP,建议选择Non Thread Safe版本。
官方并不建议你将Non Thread Safe 应用于生产环境,所以我们选择Thread Safe 版本的PHP来使用。

转载的

magic_quotes_gpc作用

转载自:http://blog.163.com/wangzhenbo85@126/blog/static/101363282201192242358226/
当php.ini设置magic_quotes_sybase为on时会覆盖magic_quotes_gpc为on的处理,然而magic_quotes_sybase仅仅是转义了nullbyte和把'变成了''
set_magic_quotes_runtime() 可以让程序员在代码中动态开启或关闭 magic_quotes_runtime,set_magic_quotes_runtime(1) 表示开启,set_magic_quotes_runtime(0) 则表示关闭。当set_magic_quotes_runtime(1)时,从数据库或通过fread之类的函数读取的文本,将自动对' "和\自动加上反斜杠\进行转义,防止溢出。这在对数据库的数据进行转移的时候非常有用。但在一般情况下,应当将其关闭,否则从数据库读取出来的数据单引 号、双引号和反斜杠都会被加上\,导致显示不正常。像Discuz,PHPWind都在公共文件的头部加上一句 set_magic_quotes_runtime(0); 强制关闭 magic_quotes_runtime 。
magic_quotes_gpc 和 magic_quotes_runtime 的区别在于,magic_quotes_gpc 是对通过GET、POST、COOKIE传递的数据进行转义,一般在数据入库前要先进行转义,magic_quotes_gpc不能在代码中动态开启或关 闭,需要到php.ini将magic_quotes_gpc设置为on或off,代码中可以用get_magic_quotes_gpc获取 magic_quotes_gpc的状态

一 描叙
magic_quotes_gpc为on时,php在注册变量时会调用addslashes()函数处理[既转义单引号、双引号、反斜线和 nullbyte],但php.ini中还有另外一个选项影响着magic_quotes_gpc和addslashes()函数:当php.ini设置 magic_quotes_sybase为on时会覆盖magic_quotes_gpc为on的处理,然而magic_quotes_sybase仅仅 是转义了nullbyte和把'变成了''

php操作html元素,使用PHP Simple HTML DOM Parser

今天需要一个操作html元素的的功能,记得php有xml的,但是用的真心少,在网上搜下教程,没想到还有PHP Simple HTML DOM Parser这个开源项目,看了下介绍,可以像jquery那样操作html,赶紧下载下来体验下得意
代码如下
header('Content-type:text/html;charset=gb2312;');
//首先引入类文件
require 'simple_html_dom.php';
//读取文件里面的内容
$str=file_get_contents('tbody.txt');
//实例化对象
$html=new simple_html_dom();
//存放取出数据的数组
$temp_arr=array();
//解析html字符串
$html->load($str);
//循环取出的变量,因为是要取出tr下面的某几个td里面的内容,所以这里先查找出所有tr
foreach ($html->find('tr') as $key => $value) {
$temp=array();
//第一行是边个的标题,跳过
if ($key==0) {
continue;
}
//循环tr下面的td
foreach ($value->children() as $key_1 => $value_1) {
//因为这个表格是不规则的,用到了rowspan,所以这里这样操作了下
if (isset($value_1->attr['class'])&&$value_1->attr['class']=='xxx') {
//find是找出当前元素下面的标签,后面没数字的话应该就是返回所有的,有数字的话就是返回指定的那一个
$temp[]=trim($value_1->find('a',0)->plaintext);
$temp[]=trim($value->children($key_1+3)->plaintext);
$temp[]=trim($value->children($key_1+4)->plaintext);
$temp[]=trim($value->children($key_1+5)->plaintext);
$temp_arr[]=$temp;
}
continue;
}
}
var_dump($temp_arr);
?>

中文文档网址:http://www.ecartchina.com/php-simple-html-dom/manual.htm

pdo使用记录

<?php
/**
 * Created by PhpStorm.
 * User: jin
 * Date: 2015/9/25
 * Time: 11:54
 */
class MysqlDb
{
    static $dbArr = array();
    private $conection = null;
    private $dsn = null;
    private $usernName = null;
    private $userPwd = null;
    private $parameter = null;
    function __construct($username,$pwd,$dbname,$host,$parameter = array())
    {
        $this->dsn='mysql:host='.$host.';dbname='.$dbname;
        $this->usernName = $username;
        $this->userPwd = $pwd;
        $this->parameter = $parameter;
        $this->connect();
    }
    private function connect()
    {
        //当初始化对象失败,也就是连接数据库失败时,会抛出PDOException异常
        try{
            //实例化对象
            $this->conection = new PDO($this->dsn,$this->usernName,$this->userPwd,$this->parameter);
            //设置编码
            $this->conection->exec('set names utf8');
            return true;
        }catch(PDOException $e){
            //结束程序,并打印错误信息
            error_log($e->getMessage(), 0);
            return $e->getMessage();
        }
    }
    //写入操作
    function excute($sql,$parameter = array())
    {
        try
        {
            $prepare = $this->conection->prepare($sql);
            $res = $prepare->execute($parameter);
        }
        catch(PDOException $e)
        {
            if($e->errorInfo[0] == 70100 || $e->errorInfo[0] == 2006){
                $count = 0;
                while(!$this->connect()){
                    sleep(1);
                    echo "数据库重新连接失败(try:{$count})\n";
                    $count++;
                };
                $res = $this->excute($sql, $parameter);
            }
            else
            {
                exit($e->errorInfo[2]);
            }
        }
        return $res;
    }
    //查询操作
    function query($sql,$parameter = array())
    {
        try
        {
            $prepare = $this->conection->prepare($sql);
            $prepare->execute($parameter);
            //设置返回的是索引数组
            $prepare->setFetchMode(PDO::FETCH_ASSOC);
            //取出结果数组
            $row = $prepare->fetchAll();
        }
        catch(PDOException $e)
        {
            if($e->errorInfo[0] == 70100 || $e->errorInfo[0] == 2006){
                $count = 0;
                while(!$this->connect()){
                    sleep(1);
                    echo "数据库重新连接失败(try:{$count})\n";
                    $count++;
                };
                $res = $this->query($sql, $parameter);
            }
            else
            {
                exit($e->errorInfo[2]);
            }
        }
        return $row;
    }
    //只查询第一条
    function find($sql,$parameter = array())
    {
        $row = $this->query($sql,$parameter);
        return current($row);
    }
    //关闭连接
    function close()
    {
        $this->conection = null;
    }
    function getLastInsertId()
    {
        return $this->conection->lastInsertId();
    }
}

获取文件时间信息

filemtime ( string filename )

返回文件上次被修改的时间,出错时返回 FALSE。时间以 Unix 时间戳的方式返回,可用于 date()。
例如:

$a=filemtime("log.txt");
echo "修改时间:".date("Y-m-d H:i:s",$a).";

filectime ( string filename )

返回文件上次 inode 被修改的时间,如果出错则返回 FALSE。时间以 Unix 时间戳的方式返回。
例如:

$a=filectime("log.txt");
echo "创建时间:".date("Y-m-d H:i:s",$a).";

fileatime ( string filename )

返回文件上次被访问的时间,如果出错则返回 FALSE。时间以 Unix 时间戳的方式返回。
例如:

$a=fileatime("log.txt");
echo "修改时间:".date("Y-m-d H:i:s",$a).";