diff --git a/Helper/Tools.php b/Helper/Tools.php index 0bd737d..96d3034 100755 --- a/Helper/Tools.php +++ b/Helper/Tools.php @@ -316,5 +316,32 @@ public static function getServerIp() return $_SERVER['SERVER_ADDR']; } + /** + * 求a相对于b的路径 + * + * @param $a + * @param $b + * @return string + */ + public static function getRelativePath($a, $b) + { + $path = ''; + $arr = explode('/', $a); + $brr = explode('/', $b); +// var_dump($brr); + $same = array_intersect_assoc($arr, $brr);//获取两个数组相同的部分 +//var_dump($same); + $dir = array_diff_assoc($brr, $same); +// var_dump($dir);die; + for($i = 1; $i <= count($dir)-1; $i++) { + $path .='../'; + } + + $path .= str_replace(implode('/',$same).'/','', $a); + + return $path; + } + + } diff --git a/array_merge_sort.php b/array_merge_sort.php index 9b3e5ba..b6ef37d 100644 --- a/array_merge_sort.php +++ b/array_merge_sort.php @@ -87,4 +87,25 @@ function array_merge_sort2($a, $b) return $result; } -print_r(array_merge_sort2($a, $b)); \ No newline at end of file + +function sort_mix_array($a, $b) +{ + if(count($a) == 0) return $b; + + $result = []; + $i=0; + //以a数组中的元素为基数,将b中比基数小的先存入结果数组,再将基数存入;再取出a中的下一个数对b剩下的数组重复以上操作,直到所有元素存入结果数组 + foreach ($a as $k => $item) { + + while (isset($b[$i]) && $item > $b[$i]) { + $result[] = $b[$i]; + $i++; + } + + $result[] = $item; + } + return $result; +} + + +print_r(sort_mix_array($a, $b)); \ No newline at end of file diff --git a/index.html b/bibao.html similarity index 100% rename from index.html rename to bibao.html diff --git a/codehero3/kill_redis.php b/codehero3/kill_redis.php new file mode 100644 index 0000000..fc4d9b5 --- /dev/null +++ b/codehero3/kill_redis.php @@ -0,0 +1,61 @@ +connect('127.0.0.1', 6379); + + $cnt = $redis->sCard($cdkey); + if (!$cnt) { + echo '已经发放完毕!余量'.$cnt; + die; + } + + if (!$redis->sAdd($userkey, $userId)) { + echo "只能领取一次";die; + } + + //仓库中随机取出一个cdkey + if($cdkey = $redis->sPop($cdkey)) { + $db = new mysqli(); +// $db->connect('127.0.0.1', 'root', 'root', 'codehero', 8889); + $db->connect('127.0.0.1', 'root', '12345678', 'codehero', 3306); + $db->set_charset('utf8'); + + $time = time(); + $db->query("BEGIN"); + $db->query("UPDATE `cdkeys` SET `status` = 1 WHERE `id` = {$cdkey} ADN `status`=0"); + $db->query("INSERT INTO `log` (`cdkey`, `userid`, `createTime`) VALUES ({$cdkey}, {$userId}, {$time})"); + $db->query("COMMIT"); + + echo "success";die; + } else { + echo "已经发放完毕!";die; + } + + +} \ No newline at end of file diff --git a/codehero3/makeData.php b/codehero3/makeData.php new file mode 100644 index 0000000..ecbe66f --- /dev/null +++ b/codehero3/makeData.php @@ -0,0 +1 @@ +connect('127.0.0.1', 'root', '12345678', 'codehero', 3306); $db->set_charset('utf8'); $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $time = time(); for($i=1;$i<=10000;$i++) { $redis->sAdd('cd_keys', $i); // $cdkey = rand(0,10000000); // $db->query("INSERT INTO `cdkeys` (`cdkey`) VALUES ($cdkey)"); } echo 'success'; \ No newline at end of file diff --git a/deep_in_array.php b/deep_in_array.php index 02ff120..77399b2 100644 --- a/deep_in_array.php +++ b/deep_in_array.php @@ -6,9 +6,9 @@ * Time: 12:55 PM */ -error_reporting(E_ALL); + /** - * 给定一个二维数组,数组每行从左到右都是递增的;没列也是递增的。 + * 给定一个二维数组,数组每行从左到右都是递增的;每列也是递增的。 * 请完成一个函数,输入如上二维数组和一个整数,函数功能为判断该整数是都存在于数组中。 * 时间复杂度尽可能低。(请说明时间复杂度) */ @@ -26,7 +26,7 @@ var_dump( find($arr, $findParam) ); /** - * 冒泡——时间复杂付O(n^2) + * 冒泡——时间复杂付O(n²) * @param $arr * @param $findParam * @return bool @@ -47,62 +47,4 @@ function find($arr, $findParam) { } -/** - * 循环方式——冒泡 - * @param array $arr 待查二维数组 - * @param int $findParam - * @return bool - * 时间复杂度O(n²) - */ -function deep_in_array($arr, $findParam) -{ - //下面是一个例子: - //二维数组: - //$arr = array([1,2,8,9],[2,4,9,12], [4,7,10,13], [6,8,11,15]); - //数字:9 - foreach ($arr as $item) { - foreach ($item as $value) { - if ($value == $findParam) return true; - if ($value > $findParam) continue; - } - } - return false; -} - - -/** - * 利用in_array - * @param $arr - * @param $findParam - * @return bool - * 时间复杂度O(n²) - */ -function deep_in_array2($arr, $findParam) -{ - foreach ($arr as $item) { - //in_array严格模式性能更高,因为松模式会将字符型数字串转换为长整型 - //使用时注意数据类型 - if (in_array($findParam, $item, true)) return true; - } - return false; -} - -/** - * 递归实现,优势,可以进行更高阶数组的判断 - * - * 时间复杂度? - */ -function deep_in_array3($arr, $findParam){ - if (is_array($arr)) { - foreach ($arr as $value) { - if (is_array($value) && deep_in_array3($value, $findParam)) return true; - if ($value == $findParam) return true; - if ($value > $findParam) continue; - } - } - if ($arr == $findParam) return true; - return false; -} - - diff --git a/output.php b/output.php index 4d82dca..38c47a6 100644 --- a/output.php +++ b/output.php @@ -10,7 +10,7 @@ //var_dump(is_null([])); //var_dump(false == []); //var_dump([] == null); - +//die; //utf-8中文占3个字符 //echo mb_substr($str = '欢迎来我中国,you are welocme!', 0, 7)."\n"; //echo substr($str = '欢迎来我中国,you are welocme!', 0, 7); @@ -26,8 +26,8 @@ print $test.$array."\n"; -print_r($array); +//print_r($array); -var_dump($array); +//var_dump($array); ?> \ No newline at end of file diff --git a/test.php b/test.php index 08d8209..4741650 100644 --- a/test.php +++ b/test.php @@ -1 +1 @@ -x; }; // 闭包函数绑定到类 A 上 //$getX = $getXCB->bindTo(new A, 'A'); //echo $getX(); //print(PHP_EOL); echo $getXCB->call(new A, 'A'); \ No newline at end of file +x; }; // 闭包函数绑定到类 A 上 //$getX = $getXCB->bindTo(new A, 'A'); //echo $getX(); //print(PHP_EOL); echo $getXCB->call(new A, 'A'); \ No newline at end of file diff --git a/xss.html b/xss.html new file mode 100644 index 0000000..69fde58 --- /dev/null +++ b/xss.html @@ -0,0 +1 @@ + xss漏洞广告页面 敏感词汇 \ No newline at end of file