This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 简单的树结构,可以插入,删除,检测某节点是否存在 | |
*/ | |
class XcTree | |
{ | |
// tree structure | |
// $tree = array( | |
// array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
*/ | |
class MoneyDec | |
{ | |
public $val; | |
public $pr; | |
public $int; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _get($key = null, $or = null) | |
{ | |
if ($key === null) | |
return $_GET; | |
return isset($_GET[$key]) ? trim($_GET[$key]) : $or; | |
} | |
function _post($key = null, $or = null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL | E_STRICT); | |
set_time_limit(1000); | |
$root_url = 'http://mitpress.mit.edu/sicp/full-text/book/'; | |
$start_url = 'http://mitpress.mit.edu/sicp/full-text/book/book.html'; | |
$save_root = 'sicp'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHP lint | |
* 用法:放在www目录下,用浏览器访问即可 | |
* 作者:王霄池 | |
* 有 bug,请去打击王霄池 | |
*/ | |
ini_set('display_errors', 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL | E_STRICT); | |
/** | |
* 这个 JSON 解析器还有以下问题: | |
* 不能处理utf编码 | |
* 用的是递归,可能会产生 stack overflow | |
* 整体需要扫描两遍以上,效率低 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WeiChatAuth | |
{ | |
/** | |
* 获取access_token | |
* | |
* 一定通过网络获取 | |
*/ | |
public static function getAccessToken($appid, $appsecret) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// convert with float | |
function my_base_convert($n, $from_base, $to_base) | |
{ | |
// when int | |
if (intval($n) == floatval($n)) { | |
$n = intval($n); | |
return base_convert($n, $from_base, $to_base); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
set_time_limit(0); // 无限制的跑下去,跑到天荒地老 | |
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
// 绑定地址和端口 | |
if (!socket_bind($socket, $config['tcp.host'], $config['tcp.port'])) { | |
die('socket bind fail'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) { | |
$msg = "$errno $errstr in $errfile:$errline "; | |
$trace = debug_backtrace(); | |
array_shift($trace); | |
$trace = array_map(function ($e) { | |
$function = $e['function']; | |
if (isset($e['class'])) { | |
$function = $e['class'].$e['type'].$function; | |
} |