分类目录归档:PHP

php5.5.17编译报 can't open file: ext/opcache/.libs/opcache.a错误

崩溃了,一天编译了4此,发现到 can't open file: ext/opcache/.libs/opcache.a 这里就挂了,为什么呢?

应该是homebrew的php5.5编译有bug,最后试了下用--disable-opcache去掉opcache模块。安装完成,使用pecl install ZendOpcache-7.0.3

单独安装opcache模块。

成功搞定mac下brew安装php5.5.17

enjoy it!

php function_exists函数未定义问题

前几天踩了一个php的坑,在写函数的时候添加了一个function_exists判断函数是否已经定义,

结果爆出了函数未定义的错误,经过分析发现函数定义我放到文件最后面了,将这块代码提到最前面就没问题,

function_exists判断是一个php语句,只有执行到这里的时候里面的函数才会被解析,

 

哈哈,一个不错得坑

windows7 64位 php5.3安装php_mongo.dll方法

windows 7 64位系统安装php mongodb 模块时需要选择64位的dll才能正确使用目前最新支持的是php_mongo-1.3.2RC1-5.3-vc9-x86_64.dll 这个dll,我的php是TS模式的。试了几次都没成功最后用最新版的1.3.2RC1的就成功了。

dll的下载地址为:https://github.com/mongodb/mongo-php-driver/downloads 支持php5.2,php5.3,php5.4三个版本的。 最新版本是1.3.2RC1

玩的开心!!!

PHPTidy 纠错html代码

html抓取的时候经常会出现html代码错乱问题,怎么修复呢?这就需要PHPtidy这个利器了。一般php会默认带的。
具体用法就不多说了。直接贴代码:

/**
* 清理html并纠错
*/
function tidyHtml($html) {
$b = mb_detect_encoding($html);
if($b != 'UTF-8'){
$html = mb_convert_encoding($html, 'UTF-8');
}
$tidy = new tidy;
$tidy->parseString($html,array(),'UTF8');

$tidy->cleanRepair();
$txt = $tidy->html()->value;

preg_match_all('/\(.*)\<\/body\>/msi',$txt,$ret);
$ret = $ret[1][0];
// $ret = strip_tags($ret,'

php xml to array转换函数

php解析xml到php数组是个问题,不太好搞。看了下往上经典的处理方式就是

$b = json_decode(json_encode((array)$xml),true);

这个方式有个问题就是<![CDATA[会被处理为空得数据

不得已自己写了一个函数处理这个问题


function xml2Array($xml) {

$arr = null;

if($xml->attributes() ) {

foreach($xml->attributes() as $k=>$v) {

$arr['@a'][$k]= $v->__toString();

}

}

/*

if($xml->getName() == 'description') {

var_dump($xml);

var_dump($xml->count());exit;

}

*/

if($xml->count()) {

foreach($xml as $v) {

$va = $v->getName();

if($xml->count() > 0){

$va = $v->getName();

if(count($xml->$va) > 1) {

$arr[$v->getName()][]= xml2Array($v);

} else {

$arr[$v->getName()] = xml2Array($v);

}

} else {

$arr[$v->getName()] = xml2Array($v);

}

}

} else {

if($arr['@a']) {

$arr['_v'] = $xml->__toString();

} else {

$arr = $xml->__toString();

}

}

return $arr;

}