自己写的采集lintcode.com上面的试题

public function index(){
 				set_time_limit(0);


				$handle = array(
					"http://www.lintcode.com/zh-cn/problem/merge-intervals",
					"http://www.lintcode.com/zh-cn/problem/count-1-in-binary",
					"http://www.lintcode.com/zh-cn/problem/fibonacci",
					"http://www.lintcode.com/zh-cn/problem/delete-node-in-the-middle-of-singly-linked-list",
					"http://www.lintcode.com/zh-cn/problem/subtree",
					"http://www.lintcode.com/zh-cn/problem/coins-in-a-line",
					"http://www.lintcode.com/zh-cn/problem/best-time-to-buy-and-sell-stock-iv",
					"http://www.lintcode.com/zh-cn/problem/house-robber",
					"http://www.lintcode.com/zh-cn/problem/candy",
					"http://www.lintcode.com/zh-cn/problem/reverse-integer",
					"http://www.lintcode.com/zh-cn/problem/gray-code",
					"http://www.lintcode.com/zh-cn/problem/divide-two-integers",
					"http://www.lintcode.com/zh-cn/problem/plus-one",
					"http://www.lintcode.com/zh-cn/problem/add-binary",
					"http://www.lintcode.com/zh-cn/problem/assignment-operator-overloading-c-only",
					"http://www.lintcode.com/zh-cn/problem/print-numbers-by-recursion",
					"http://www.lintcode.com/zh-cn/problem/container-with-most-water",
					"http://www.lintcode.com/zh-cn/problem/longest-substring-without-repeating-characters",
					"http://www.lintcode.com/zh-cn/problem/the-smallest-difference",
					"http://www.lintcode.com/zh-cn/problem/count-of-smaller-number-before-itself",
					"http://www.lintcode.com/zh-cn/problem/valid-sudoku",
					"http://www.lintcode.com/zh-cn/problem/expression-tree-build",
					"http://www.lintcode.com/zh-cn/problem/convert-expression-to-reverse-polish-notation",
					"http://www.lintcode.com/zh-cn/problem/building-outline",
					"http://www.lintcode.com/zh-cn/problem/count-of-smaller-number",
					"http://www.lintcode.com/zh-cn/problem/permutation-sequence",
					"http://www.lintcode.com/zh-cn/problem/expression-evaluation",
					"http://www.lintcode.com/zh-cn/problem/intersection-of-two-linked-lists",
					"http://www.lintcode.com/zh-cn/problem/spiral-matrix",
					"http://www.lintcode.com/zh-cn/problem/trapping-rain-water",
					"http://www.lintcode.com/zh-cn/problem/sliding-window-maximum",
					"http://www.lintcode.com/zh-cn/problem/first-missing-positive",
					"http://www.lintcode.com/zh-cn/problem/interval-sum",
					"http://www.lintcode.com/zh-cn/problem/interval-minimum-number",
					"http://www.lintcode.com/zh-cn/problem/singleton",
					"http://www.lintcode.com/zh-cn/problem/segment-tree-modify",
					"http://www.lintcode.com/zh-cn/problem/segment-tree-query",
					"http://www.lintcode.com/zh-cn/problem/permutation-index",
					"http://www.lintcode.com/zh-cn/problem/wildcard-matching",
					"http://www.lintcode.com/zh-cn/problem/maximum-product-subarray",
					"http://www.lintcode.com/zh-cn/problem/gas-station",
					"http://www.lintcode.com/zh-cn/problem/matrix-zigzag-traversal",
					"http://www.lintcode.com/zh-cn/problem/largest-number",
					"http://www.lintcode.com/zh-cn/problem/wood-cut",
					"http://www.lintcode.com/zh-cn/problem/delete-digits"
				);
				


				
			foreach($handle as $h){
				 
				$data = array();


 				$content = file_get_contents($h);
			 	/*去除掉所有的空格*/		
			 	$content = str_replace(array("\r", "\n"," "), "", $content);	


			 
			 	/*匹配了标题*/
			 	$reg = '#(.*?)#';
			 	preg_match($reg,$content,$arr);
			 	$data['title'] = $arr[1];




			 	/*匹配了简介*/
			 	$reg = '#

(.*?)

#'; preg_match($reg,$content,$arr); $data['des'] = $arr[1]; /*匹配了时间限制*/ $reg = '#Countdownlimitvariesduetodifficulty">(.*?)
#'; preg_match($reg,$content,$arr); $data['limit_time'] = (int)$arr[1]; $data['mem_limit'] = 3000; /*匹配标签*/ $reg = '#(.*?)#'; preg_match_all($reg,$content,$arr); $data['tag_list'] = implode(',',$arr[2]); /*******************获取代码*******************/ /*获取id*/ $reg = '#name="problem_id"value="(.*?)"id="problem-id">#'; preg_match($reg,$content,$id); /*获取实现的语言*/ $reg = '#(.*?)#'; preg_match($reg,$content,$lang); $reg = '#(.*?)#'; preg_match_all($reg,$lang[1],$arr); /*获取实际的代码*/ for($i=0;$i$arr[2][$i],"code"=>$code_arr['code']); } $data['init_code'] = json_encode($data['init_code']); $data['type'] = "编程题"; M('challenge_topic')->add($data); } echo "success"; }

你可能感兴趣的:(php)