Skip to content

Instantly share code, notes, and snippets.

View HikoQiu's full-sized avatar

HikoQiu HikoQiu

  • Guangdong, China
View GitHub Profile
$data = [
['A', 'B', 'C', 'D'],
['A', 'B', 'TT', 'D'],
['A', 'F', 'G', 'H'],
['11', '12', '13', '14'],
['11', '12', '13', '15'],
['18', '19', '20', '21'],
['18', 'A', '20', '21'],
];
@HikoQiu
HikoQiu / 正则匹配网页链接
Created October 17, 2014 09:38
正则匹配网页链接
$rawTitle = '<meta name="description" content="hello world">';
$res = preg_match("/<meta name=\"(\w+)\" content=\"(.*?)\">/is",$rawTitle,$booktitle);
var_dump($booktitle, $res);
$str = 'foobar: 2008';
preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);
var_dump($matches);
header("charset=utf-8;");
function StrToBin($str){
//1.列出每个字符
$arr = preg_split('/(?<!^)(?!$)/u', $str);
//2.unpack字符
foreach($arr as &$v){
$temp = unpack('H*', $v);
$v = base_convert($temp[1], 16, 2);
unset($temp);
@HikoQiu
HikoQiu / Ip2Int & Int2Ip
Created October 16, 2014 08:18
ip与整数值转换
function int2ip($num) {
$tmp = (double)$num;
return sprintf('%u.%u.%u.%u', $tmp & 0xFF, (($tmp >> 8) & 0xFF),
(($tmp >> 16) & 0xFF), (($tmp >> 24) & 0xFF));
}
function ip2int($ip) {
$n = ip2long($ip);
/** convert to network order */
error: RPC failed; result=22, HTTP code = 411
fatal: The remote end hung up unexpectedly
解决方式:git config http.postBuffer 524288000
@HikoQiu
HikoQiu / detect mobile user agent
Created October 13, 2014 08:23
检测手机的ua
Have my user agent code:
<?php
/* USER-AGENTS
================================================== */
function check_user_agent ( $type = NULL ) {
$user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
if ( $type == 'bot' ) {
// matches popular bots
@HikoQiu
HikoQiu / YII 操作原生的SQL.
Created October 9, 2014 07:34
YII 操作原生SQL.
$autonumberquery = "ALTER TABLE {{survey_{$iSurveyID}}} AUTO_INCREMENT = ".$row['autonumber_start'];
$result = @Yii::app()->db->createCommand($autonumberquery)->execute();
@HikoQiu
HikoQiu / YII model resetCache
Created October 9, 2014 07:27
YII 更新字段之后,保证新的数据马上被使用
$survey = Survey::model()->findByAttributes(array('sid' => $iSurveyID));
$survey->anonymized = Yii::app()->request->getPost('anonymized');
$survey->datestamp = Yii::app()->request->getPost('datestamp');
$survey->ipaddr = Yii::app()->request->getPost('ipaddr');
$survey->refurl = Yii::app()->request->getPost('refurl');
$survey->savetimings = Yii::app()->request->getPost('savetimings');
$survey->save();
Survey::model()->resetCache(); // Make sure the saved values will be picked up
$sTableName=Yii::app()->db->tablePrefix.str_replace(array('{','}'),array('',''),$sTableName);
return in_array($sTableName,Yii::app()->db->schema->getTableNames());
// 刷新新的数据表(比如在修改表名称之后执行该操作)
Yii::app()->db->schema->refresh();
$sQuery = "SELECT p.entity_id, p.uid, u.users_name, u.full_name FROM {{permissions}} AS p INNER JOIN {{users}} AS u ON p.uid = u.uid
WHERE p.entity_id = :surveyid AND u.uid != :userid and p.entity='survey'
GROUP BY p.entity_id, p.uid, u.users_name, u.full_name
ORDER BY u.users_name";
$iUserID=Yii::app()->user->getId();
return Yii::app()->db->createCommand($sQuery)->bindParam(":userid", $iUserID, PDO::PARAM_INT)->bindParam("surveyid", $surveyid, PDO::PARAM_INT)->query()->readAll(); //Checked