Skip to content

Instantly share code, notes, and snippets.

@bjzhush
bjzhush / gist:874ed7596e4324c0a4577a37bfe651b8
Created July 25, 2018 12:42
流式读取大文件的方法
<?php
$lines = [];
$handle = fopen('x.txt', "r");
if (!$handle){
exit('error');
}
while(!feof($handle)) {
$line = trim(fgets($handle));
}
@bjzhush
bjzhush / mysql_data.php
Created December 12, 2016 03:01 — forked from lifesign/mysql_data.php
mysql 生成数据字典
<?php
/**
* 生成mysql数据字典
*/
// 配置数据库
$database = array();
$database['DB_HOST'] = '127.0.0.1';
$database['DB_NAME'] = 'test';
$database['DB_USER'] = 'testuser';
$database['DB_PWD'] = '123456';
php.ini (php 5.6)
; add by zs
zend_extension=xdebug.so
xdebug.trace_output_dir = /tmp/traces
;代码跟踪日志文件格式
xdebug.trace_output_name = trace.%c.%p
;;trace中显示函数的参数值,这个很有用,待会细说
xdebug.collect_params = 4
xdebug.collect_includes = On
xdebug.collect_return = On
@bjzhush
bjzhush / gist:afd2b2b8a4cc08cf530d
Created August 27, 2015 09:00
Exception handler
<?php
function zsExceptionHandler(\Exception $e)
{
$logData = '__________Start_____________'.PHP_EOL;
$logData .= '↓↓↓'.date('Y-m-d H:i:s').PHP_EOL;
$logData .= '↓↓↓ Message'.PHP_EOL;
$logData .= $e->getMessage().PHP_EOL;
$logData .= '↓↓↓ Code'.PHP_EOL;
@bjzhush
bjzhush / gist:32bd70c0f40ce2cdc333
Created August 21, 2015 04:44
转换编码,超级好用的
mb_convert_encoding($str, 'utf-8', 'GBK,UTF-8,ASCII');
//可以用curl抓个GBK UTF8的来测试下
// zend2 DB Mysql
$oSelect = new Select();
$oSelect->columns(array('status'))
->from($this->tableName)
->where(array('sns_union_id = ?' => $snsUnionId, 'sns_type = ?' => $snsType))
->limit(1);
$draftArr = $this->executeSelect($oSelect);
$draftObj = current($draftArr);
@bjzhush
bjzhush / fallback_to_global_namespace.php
Created August 1, 2015 07:41
Using namespaces: fallback to global function/constant
<?php
namespace A\B\C;
class Exception extends \Exception {}
$a = new Exception('hi'); // $a is an object of class A\B\C\Exception
$b = new \Exception('hi'); // $b is an object of class Exception
$c = new ArrayObject; // fatal error, class A\B\C\ArrayObject not found
//http://php.net/manual/en/language.namespaces.fallback.php
<?php
echo "This is my first gist";