Home > Backend Development > PHP Tutorial > Examples to explain PHP search engine class_PHP tutorial

Examples to explain PHP search engine class_PHP tutorial

WBOY
Release: 2016-07-15 13:34:49
Original
879 people have browsed it

We have introduced you in detail about

PHP search engine class 1. Class files:

  1. class grabble{  
  2. var $filename;  
  3. var $html;  
  4. var $urls = array(); //url历史  
  5. var $url ;  
  6. var $url_1;  
  7. function grabble(){  
  8. set_time_limit(3600);   
  9. }  
  10. function set($_filename){  
  11. $this->filename = $_filename;  
  12. array_push ($this->url, $_filename);   
  13. }//end.set;  
  14. function set_url($_url){  
  15. eregi('(^http://.*[^/]).*' , $_url , $array);  
  16. $this->url = $array[1] . "/";   
  17. eregi('(^http://.*[^/]).*' , $_url , $array);  
  18. //print_r($array);  
  19. $this->url_1 = $array[1];  
  20. }  
  21. function get(){  
  22. }//end.get;  
  23. function get_html($_filename=null){  
  24. $this->filename = $_filename;  
  25. $this->html = @implode('', file($_filename)) ;  
  26. return $this->html;  
  27. }//end.get_html;  
  28. function get_title($_str=null){  
  29. preg_match_all("/<title>(.*)</title>
    /Uis", $_str, $matches);  
  30. return $matches[1][0];  
  31. }//end.get_title;  
  32. function get_img($_str=null){  
  33. preg_match_all("/<imgs+[^>]*s*srcs*=
    s*(['"]?)([^'"
    >s]*)1s*[^>]*>/i", 
    $_str, $arr);  
  34. print_r($arr[2]);  
  35. }  
  36. function get_link($_str=null){   
  37. preg_match_all("/<a.*href=['|"](.+)?
    ['|"].*
    >.+</a>/Uis", $_str, $arr);   
  38. //print_r($arr);  
  39. return $arr[1];  
  40. }//end.get_link;  
  41. function get_link_name($_str=null){   
  42. preg_match_all("/<a.*href=['|"](.+)?
    ['|"].*
    >(.+)</a>/Uis", $_str, $arr);  
  43. return $arr[2];  
  44. }//end.get_link_name;  
  45. function link_list($_url=null, $_c=0){  
  46. eregi('(^http://.*)/.*' , $_url , $array);  
  47. $_url_0 = $array[1];  
  48. $_html = $this->get_html($_url);  
  49. $_link = $this->get_link($_html);  
  50. $_list = $this->get_link_name($_html);  
  51. $s = "";  
  52. for($i=0;$i<count($_link);$i++){  
  53. $s ."
    "
     . "<INPUT TYPE='checkbox' 
    NAME='link_name[]' value='" .$_link[$i]. "' 
    />" . $_list[$i] . "  ";  
  54. echo "<br/>" . "<INPUT TYPE='checkbox' 
    NAME='link_name[]' value='" .$_link[$i]. "' 
    />" . $_list[$i] . "  ";  
  55. echo "<a href='" . $_url_0 . "/" . $_link[$i]
     . "'
     target='_blank'>" . $_url_0 . "/" . 
    $_link[$i] . "
    a>";   
  56. if($_c < 3){  
  57. if(eregi('^[$_url_0|mailto:].*' ,$_link[$i])){   
  58. echo "<a href='" . $_link[$i] . "' 
    target='_blank'>" . $_link[$i] . "a>";   
  59. $s .= $this->link_list( $_link[$i] , $_c+1);  
  60. }  
  61. elseif(!eregi('^[http://|ftp://|file:///].
    *' ,$_link[$i])){  
  62. $s .= $this->link_list( $_url_0 . "/" . $_link[$i] , $_c+1);  
  63. }  
  64. }  
  65. }  
  66. return $s;  
  67. }//end.link_list;  
  68. }//end.grabble. 

PHP搜索引擎类2.调用实例:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>require_once("grabble.<br />class.php");  </span></li><li class="alt"><span>$</span><span class="attribute">gf</span><span> = </span><span class="attribute-value">new</span><span> grabble();  </span></li><li><span>echo $gf-</span><span class="tag">></span><span>link_list(<br>'http://10.22.65.101/');  </span></span></li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol><br>
Copy after login

The above is the related usage of PHP search engine class.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445961.htmlTechArticleWe have introduced in detail the PHP search engine class 1. Class file: classgrabble{ var$filename; var$ html; var$ urls = array ();//url history var$url; var$url_1; functiongrabble(){ se...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template