1 //获得当前的脚本网址
2 function get_php_url(){
3 if(!empty($_SERVER["REQUEST_URI"])){
4 $scriptName = $_SERVER["REQUEST_URI"];
5 $nowurl = $scriptName;
6 }else{
7 $scriptName = $_SERVER["PHP_SELF"];
8 if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;
9 else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
10 }
11 return $nowurl;
12 }
13 //把全角数字转为半角数字
14 function GetAlabNum($fnum){
15 $nums = array("0","1","2","3","4","5","6","7","8","9");
16 $fnums = "0123456789";
17 for($i=0;$i<=9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);
18 $fnum = ereg_replace("[^0-9\.]|^0{1,}","",$fnum);
19 if($fnum=="") $fnum=0;
20 return $fnum;
21 }
22 //去除HTML标记
23 function Text2Html($txt){
24 $txt = str_replace(" "," ",$txt);
25 $txt = str_replace("<","<",$txt);
26 $txt = str_replace(">",">",$txt);
27 $txt = preg_replace("/[\r\n]{1,}/isU","<br/>\r\n",$txt);
28 return $txt;
29 }
30
31 //清除HTML标记
32 function ClearHtml($str){
33 $str = str_replace('<','<',$str);
34 $str = str_replace('>','>',$str);
35 return $str;
36 }
37 //相对路径转化成绝对路径
38 function relative_to_absolute($content, $feed_url) {
39 preg_match('/(http|https|ftp):\/\//', $feed_url, $protocol);
40 $server_url = preg_replace("/(http|https|ftp|news):\/\//", "", $feed_url);
41 $server_url = preg_replace("/\/.*/", "", $server_url);
42
43 if ($server_url == '') {
44 return $content;
45 }
46
47 if (isset($protocol[0])) {
48 $new_content = preg_replace('/href="\//', 'href="'.$protocol[0].$server_url.'/', $content);
49 $new_content = preg_replace('/src="\//', 'src="'.$protocol[0].$server_url.'/', $new_content);
50 } else {
51 $new_content = $content;
52 }
53 return $new_content;
54 }
55 //取得所有链接
56 function get_all_url($code){
57 preg_match_all('/<a\s+href=["|\']?([^>"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/i',$code,$arr);
58 return array('name'=>$arr[2],'url'=>$arr[1]);
59 }
60
61 //获取指定标记中的内容
62 function get_tag_data($str, $start, $end){
63 if ( $start == '' || $end == '' ){
64 return;
65 }
66 $str = explode($start, $str);
67 $str = explode($end, $str[1]);
68 return $str[0];
69 }
70 //HTML表格的每行转为CSV格式数组
71 function get_tr_array($table) {
72 $table = preg_replace("'<td[^>]*?>'si",'"',$table);
73 $table = str_replace("</td>",'",',$table);
74 $table = str_replace("</tr>","{tr}",$table);
75 //去掉 HTML 标记
76 $table = preg_replace("'<[\/\!]*?[^<>]*?>'si","",$table);
77 //去掉空白字符
78 $table = preg_replace("'([\r\n])[\s]+'","",$table);
79 $table = str_replace(" ","",$table);
80 $table = str_replace(" ","",$table);
81
82 $table = explode(",{tr}",$table);
83 array_pop($table);
84 return $table;
85 }
86
87 //将HTML表格的每行每列转为数组,采集表格数据
88 function get_td_array($table) {
89 $table = preg_replace("'<table[^>]*?>'si","",$table);
90 $table = preg_replace("'<tr[^>]*?>'si","",$table);
91 $table = preg_replace("'<td[^>]*?>'si","",$table);
92 $table = str_replace("</tr>","{tr}",$table);
93 $table = str_replace("</td>","{td}",$table);
94 //去掉 HTML 标记
95 $table = preg_replace("'<[\/\!]*?[^<>]*?>'si","",$table);
96 //去掉空白字符
97 $table = preg_replace("'([\r\n])[\s]+'","",$table);
98 $table = str_replace(" ","",$table);
99 $table = str_replace(" ","",$table);
100
101 $table = explode('{tr}', $table);
102 array_pop($table);
103 foreach ($table as $key=>$tr) {
104 $td = explode('{td}', $tr);
105 array_pop($td);
106 $td_array[] = $td;
107 }
108 return $td_array;
109 }
110
111 //返回字符串中的所有单词 $distinct=true 去除重复
112 function split_en_str($str,$distinct=true) {
113 preg_match_all('/([a-zA-Z]+)/',$str,$match);
114 if ($distinct == true) {
115 $match[1] = array_unique($match[1]);
116 }
117 sort($match[1]);
118 return $match[1];
119 }
2 function get_php_url(){
3 if(!empty($_SERVER["REQUEST_URI"])){
4 $scriptName = $_SERVER["REQUEST_URI"];
5 $nowurl = $scriptName;
6 }else{
7 $scriptName = $_SERVER["PHP_SELF"];
8 if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;
9 else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
10 }
11 return $nowurl;
12 }
13 //把全角数字转为半角数字
14 function GetAlabNum($fnum){
15 $nums = array("0","1","2","3","4","5","6","7","8","9");
16 $fnums = "0123456789";
17 for($i=0;$i<=9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);
18 $fnum = ereg_replace("[^0-9\.]|^0{1,}","",$fnum);
19 if($fnum=="") $fnum=0;
20 return $fnum;
21 }
22 //去除HTML标记
23 function Text2Html($txt){
24 $txt = str_replace(" "," ",$txt);
25 $txt = str_replace("<","<",$txt);
26 $txt = str_replace(">",">",$txt);
27 $txt = preg_replace("/[\r\n]{1,}/isU","<br/>\r\n",$txt);
28 return $txt;
29 }
30
31 //清除HTML标记
32 function ClearHtml($str){
33 $str = str_replace('<','<',$str);
34 $str = str_replace('>','>',$str);
35 return $str;
36 }
37 //相对路径转化成绝对路径
38 function relative_to_absolute($content, $feed_url) {
39 preg_match('/(http|https|ftp):\/\//', $feed_url, $protocol);
40 $server_url = preg_replace("/(http|https|ftp|news):\/\//", "", $feed_url);
41 $server_url = preg_replace("/\/.*/", "", $server_url);
42
43 if ($server_url == '') {
44 return $content;
45 }
46
47 if (isset($protocol[0])) {
48 $new_content = preg_replace('/href="\//', 'href="'.$protocol[0].$server_url.'/', $content);
49 $new_content = preg_replace('/src="\//', 'src="'.$protocol[0].$server_url.'/', $new_content);
50 } else {
51 $new_content = $content;
52 }
53 return $new_content;
54 }
55 //取得所有链接
56 function get_all_url($code){
57 preg_match_all('/<a\s+href=["|\']?([^>"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/i',$code,$arr);
58 return array('name'=>$arr[2],'url'=>$arr[1]);
59 }
60
61 //获取指定标记中的内容
62 function get_tag_data($str, $start, $end){
63 if ( $start == '' || $end == '' ){
64 return;
65 }
66 $str = explode($start, $str);
67 $str = explode($end, $str[1]);
68 return $str[0];
69 }
70 //HTML表格的每行转为CSV格式数组
71 function get_tr_array($table) {
72 $table = preg_replace("'<td[^>]*?>'si",'"',$table);
73 $table = str_replace("</td>",'",',$table);
74 $table = str_replace("</tr>","{tr}",$table);
75 //去掉 HTML 标记
76 $table = preg_replace("'<[\/\!]*?[^<>]*?>'si","",$table);
77 //去掉空白字符
78 $table = preg_replace("'([\r\n])[\s]+'","",$table);
79 $table = str_replace(" ","",$table);
80 $table = str_replace(" ","",$table);
81
82 $table = explode(",{tr}",$table);
83 array_pop($table);
84 return $table;
85 }
86
87 //将HTML表格的每行每列转为数组,采集表格数据
88 function get_td_array($table) {
89 $table = preg_replace("'<table[^>]*?>'si","",$table);
90 $table = preg_replace("'<tr[^>]*?>'si","",$table);
91 $table = preg_replace("'<td[^>]*?>'si","",$table);
92 $table = str_replace("</tr>","{tr}",$table);
93 $table = str_replace("</td>","{td}",$table);
94 //去掉 HTML 标记
95 $table = preg_replace("'<[\/\!]*?[^<>]*?>'si","",$table);
96 //去掉空白字符
97 $table = preg_replace("'([\r\n])[\s]+'","",$table);
98 $table = str_replace(" ","",$table);
99 $table = str_replace(" ","",$table);
100
101 $table = explode('{tr}', $table);
102 array_pop($table);
103 foreach ($table as $key=>$tr) {
104 $td = explode('{td}', $tr);
105 array_pop($td);
106 $td_array[] = $td;
107 }
108 return $td_array;
109 }
110
111 //返回字符串中的所有单词 $distinct=true 去除重复
112 function split_en_str($str,$distinct=true) {
113 preg_match_all('/([a-zA-Z]+)/',$str,$match);
114 if ($distinct == true) {
115 $match[1] = array_unique($match[1]);
116 }
117 sort($match[1]);
118 return $match[1];
119 }