日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

    歡迎訪問 生活随笔!

    生活随笔

    當前位置: 首頁 > 运维知识 > windows >内容正文

    windows

    有用的函数-系统采集

    發布時間:2023/12/16 windows 30 豆豆
    生活随笔 收集整理的這篇文章主要介紹了 有用的函数-系统采集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

    本帖最后由 leon_studio 于 2009-5-4 21:04 編輯

    1.采集表格中的內容為數組

  1. function get_td_array($table) {
  2. ? ?? ???$table = preg_replace("'<table[^>]*?>'si","",$table);
  3. ? ?? ???$table = preg_replace("'<tr[^>]*?>'si","",$table);
  4. ? ?? ???$table = preg_replace("'<td[^>]*?>'si","",$table);
  5. ? ?? ???$table = str_replace("</tr>","{tr}",$table);
  6. ? ?? ???$table = str_replace("</td>","{td}",$table);
  7. ? ?? ???//去掉 HTML 標記
  8. ? ?? ???$table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);?
  9. ? ?? ???//去掉空白字符
  10. ? ?? ???$table = preg_replace("'([rn])[s]+'","",$table);
  11. ? ?? ???$table = str_replace(" ","",$table);
  12. ? ?? ???$table = str_replace(" ","",$table);
  13. ? ?? ???$table = explode('{tr}', $table);
  14. ? ?? ???array_pop($table); //OSPHP.com.CN
  15. ? ?? ???foreach ($table as $key=>$tr) {
  16. ? ?? ?? ?? ?? ? $td = explode('{td}', $tr);
  17. ? ?? ?? ?? ?? ? array_pop($td);
  18. ? ?? ?? ?? ?$td_array[] = $td;
  19. ? ?? ???}
  20. ? ?? ???return $td_array;
  21. }
  22. 復制代碼 2.取得某行代碼中間的字符串

  23. /**
  24. +----------------------------------------------------------
  25. * 取得某行代碼之間的字符串
  26. +----------------------------------------------------------
  27. * 例: echo get_innerhtml("<tr><td height=20>something</td></tr>", "td");? ?//will print "something".
  28. +----------------------------------------------------------
  29. */
  30. function get_innerhtml($html,$label) {
  31. ? ? $result_arr = preg_split("/<\/".$label.">/i",$html);
  32. ? ? $pattern = "/<".$label.".*?>/i";
  33. ? ? for ($i = 0; $i < count($result_arr); $i++) {
  34. ? ?? ???list($left, $right) = preg_split($pattern,$result_arr[$i],2);
  35. ? ?? ???$result_arr[$i] = $right;
  36. ? ? }
  37. ? ? return $result_arr;
  38. }
  39. 復制代碼 3.獲取Input的HTML代碼中的Value值

  40. //獲取Input的HTML代碼中的Value值
  41. function get_input_value($input) {
  42. ? ? $pos = stripos($input, "value=") + 6;
  43. ? ? if ($pos !== false) {
  44. ? ?? ???$input = substr($input, $pos);
  45. ? ?? ???if (substr($input, 0, 1) == "\"")
  46. ? ?? ?? ?? ?return substr($input, 1, strpos($input, "\"", 1) - 1);
  47. ? ?? ???else
  48. ? ?? ?? ?? ?return substr($input, 0, strpos($input, " ") - 1);
  49. ? ? }
  50. ? ? return false;
  51. }
  52. 復制代碼 4.獲取字符串$str中,字符串$a與字符串$b之間的字符串
  53. //獲取字符串$str中,字符串$a與字符串$b之間的字符串
  54. function getcontentbetween($a, $b, $str) {
  55. ? ? if ($str!=="" && $a!=="" && $b!=="") {
  56. ? ?? ???$start = strpos($str, $a) + strlen($a);
  57. ? ?? ???return substr($str, $start, strpos($str, $b, $start + 1) - $start);
  58. ? ? }
  59. ? ? return false;
  60. }
  61. 復制代碼 5.<br>變成回車
  62. function br2nl($text)
  63. {
  64. ? ?return??trim(preg_replace('/<br\s*/?'.'>/i', '', $text));
  65. }
  66. 復制代碼 6.換行奕成<p></p>
  67. function nl2p($text)
  68. {
  69. return str_replace(array("\r\n\r\n","\r\n","\r","\n"),"</p><p>",$text);
  70. }
  71. 復制代碼 7.獲得當前腳本網址
  72. function get_php_url(){?
  73. ? ?? ???if(!empty($_SERVER["REQUEST_URI"])){?
  74. ? ?? ?? ?? ?? ? $scriptName = $_SERVER["REQUEST_URI"];?
  75. ? ?? ?? ?? ?? ? $nowurl = $scriptName;?
  76. ? ?? ???}else{?
  77. ? ?? ?? ?? ?? ? $scriptName = $_SERVER["HP_SELF"];?
  78. ? ?? ?? ?? ?? ? if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;?
  79. ? ?? ?? ?? ?? ? else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];?
  80. ? ?? ???}?
  81. ? ?? ???return $nowurl;?
  82. }
  83. 復制代碼 8.去除html標記

  84. function Text2Html($txt){
  85. ? ?? ???$txt = str_replace("??"," ",$txt);
  86. ? ?? ???$txt = str_replace("<","&lt;",$txt);
  87. ? ?? ???$txt = str_replace(">","&gt;",$txt);
  88. ? ?? ???$txt = preg_replace("/[\r\n]{1,}/isU","<br/>\r\n",$txt);
  89. ? ?? ???return $txt;
  90. }
  91. 復制代碼 9.相對路徑轉絕對路徑
  92. function relative_to_absolute($content, $feed_url) {?
  93. ? ? preg_match('/(http|https|ftp):\/\//', $feed_url, $protocol);?
  94. ? ? $server_url = preg_replace("/(http|https|ftp|news):\/\//", "", $feed_url);?
  95. ? ? $server_url = preg_replace("/\/.*/", "", $server_url);?
  96. ? ? if ($server_url == '') {?
  97. ? ?? ???return $content;?
  98. ? ? }?
  99. ? ? if (isset($protocol[0])) {?
  100. ? ?? ???$new_content = preg_replace('/href="\//', 'href="'.$protocol[0].$server_url.'/', $content);?
  101. ? ?? ???$new_content = preg_replace('/src="\//', 'src="'.$protocol[0].$server_url.'/', $new_content);?
  102. ? ? } else {?
  103. ? ?? ???$new_content = $content;?
  104. ? ? }?
  105. ? ? return $new_content;?
  106. }
  107. 復制代碼
    10.取得所有鏈接
  108. function get_all_url($code){?
  109. ? ?? ???preg_match_all('/<a\s+href=["|\']?([^>"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/i',$code,$arr);?
  110. ? ?? ???return array('name'=>$arr[2],'url'=>$arr[1]);?
  111. }
  112. 復制代碼
    11.獲取指定標記中的內容
  113. function get_tag_data($str, $start, $end){?
  114. ? ?? ???if ( $start == '' || $end == '' ){?
  115. ? ?? ?? ?? ?? ?return;?
  116. ? ?? ???}?
  117. ? ?? ???$str = explode($start, $str);?
  118. ? ?? ???$str = explode($end, $str[1]);?
  119. ? ?? ???return $str[0];?
  120. }
  121. 復制代碼

    本帖最后由 leon_studio 于 2009-5-11 18:27 編輯

    再補充兩個
    12.獲取遠程文件內容(抓內容)
  122. /**?
  123. ? ? 獲取遠程文件內容?
  124. ? ? @param $url 文件http地址?
  125. */?
  126. function fopen_url($url)?
  127. {?
  128. ? ? if (function_exists('file_get_contents')) {?
  129. ? ?? ???$file_content = @file_get_contents($url);?
  130. ? ? } elseif (ini_get('allow_url_fopen') && ($file = @fopen($url, 'rb'))){?
  131. ? ?? ???$i = 0;?
  132. ? ?? ???while (!feof($file) && $i++ < 1000) {?
  133. ? ?? ?? ?? ?$file_content .= strtolower(fread($file, 4096));?
  134. ? ?? ???}?
  135. ? ?? ???fclose($file);?
  136. ? ? } elseif (function_exists('curl_init')) {?
  137. ? ?? ???$curl_handle = curl_init();?
  138. ? ?? ???curl_setopt($curl_handle, CURLOPT_URL, $url);?
  139. ? ?? ???curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,2);?
  140. ? ?? ???curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER,1);?
  141. ? ?? ???curl_setopt($curl_handle, CURLOPT_FAILONERROR,1);?
  142. ? ?? ???curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Trackback Spam Check');?
  143. ? ?? ???$file_content = curl_exec($curl_handle);?
  144. ? ?? ???curl_close($curl_handle);?
  145. ? ? } else {?
  146. ? ?? ???$file_content = '';?
  147. ? ? }?
  148. ? ? return $file_content;?
  149. }
  150. 復制代碼 13.去掉指定的標簽函數
  151. /*
  152. $str = "ertet<a href=\"http://www.xxxx.com\" tasdfgrget=\"_blank\">aaaabbbb?
  153. <img src=\"http://img.xxx.cn/xxxx.jpg\" width=\"760\" height=\"90\" border=\"0\" />?
  154. ? ?? ?? ?? ?</a>aaadf";?
  155. echo _strip_tags(array("a","img"),$str);?

  156. */
  157. function _strip_tags($tags_a,$str)?
  158. {?
  159. ? ? foreach ($tags_a as $tag)?
  160. ? ? {?
  161. ? ?? ???$p[]="/(<(?:\/".$tag."|".$tag.")[^>]*>)/i";?
  162. ? ? }?
  163. ? ? $return_str = preg_replace($p,"",$str);?
  164. ? ? return $return_str;?
  165. }?
  166. 14.從URL中獲取根域名
  167. [code]
  168. <?php
  169. function getUrlBase($url=''){
  170. if(!is_string($url) || empty($url)) return;
  171. $parse = parse_url($url);
  172. $host = $parse['host'];
  173. $h = explode('.', $host);

  174. //判斷是否本機域名或IP
  175. if(false === strpos($host, '.') || preg_match("/^(\d+\.){3}(\d+)$/", $host)){
  176. ??$root = $host;
  177. }elseif(preg_match("/(?:com|tel|mobi|net|org|asia|me|tv|biz|cc|name|info)(?:\.\w{2})$/", $host, $match)){
  178. ??array_pop($h);
  179. ??array_pop($h);
  180. ??$root = array_pop($h) . '.' . $match[0];
  181. }elseif(preg_match("/(?:\w{2,4})$/", $host, $match)){
  182. ??array_pop($h);
  183. ??$root = array_pop($h) . '.' . $match[0];
  184. }

  185. return $root;
  186. }
  187. 復制代碼


    總結

    以上是生活随笔為你收集整理的有用的函数-系统采集的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。