Tutorial on PHP search engine class_php

Source: Internet
Author: User
The example explains the PHP search engine class. We have introduced in detail the PHP search engine class 1. class File: classgrabble {var $ filename; var $ html; var $ urlsarray (); url history var $ url; var $ url_1; functiongrabble () {se

PHP search engine class 1. class files:

  1. Class grabble {
  2. Var $ filename;
  3. Var $ html;
  4. Var $ urls = array (); // url history
  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 ("/</Strong> (.*)</Title>
    /Uis ", $ _ str, $ matches );
  30. Return $ matches [1] [0];
  31. } // End. get_title;
  32. Function get_img ($ _ str = null ){
  33. Preg_match_all ("/S + [^>] * S * srcs * =
    S * (['"]?) ([^ '">S] *) \ 1 s * [^>] *>/I ",
    $ _ Str, $ arr );
  34. Print_r ($ arr [2]);
  35. }
  36. Function get_link ($ _ str = null ){
  37. Preg_match_all ("/ * Href = ['| "] (. + )?
    ['| "]. * >. + </ >/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 ("/ * Href = ['| "] (. + )?
    ['| "]. * >(. +) </ >/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 ($ _ Link); $ I ++ ){
  53. $ S. ="
    "." TYPE = 'checkbox'
    NAME = 'link _ name [] 'value = '". $ _ link [$ I]."'
    />". $ _ List [$ I]." ";
  54. Echo"
    "." TYPE = 'checkbox'
    NAME = 'link _ name [] 'value = '". $ _ link [$ I]."'
    />". $ _ List [$ I]." ";
  55. Echo" Href = '". $ _ url_0."/". $ _ link [$ I]
    . "'Target = '_ blank' >". $ _ Url_0 ."/".
    $ _ Link [$ I]." ";
  56. If ($ _ c< 3){
  57. If (eregi ('^ [$ _ url_0 | mailto:]. *', $ _ link [$ I]) {
  58. Echo" Href = '". $ _ link [$ I]."'
    Target = '_ blank' >". $ _ Link [$ I]." ";
  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 search engine type 2. call an instance:

 
 
  1. < ?php
  2. require_once("grabble.
    class.php");
  3. $gf = new grabble();
  4. echo $gf->link_list(
    'http://10.22.65.101/');
  5. ?>

The above describes how to use the PHP search engine class.


Sort PHP search engine class 1. class File: classgrabble {var $ filename; var $ html; var $ urls = array (); // url history var $ url; var $ url_1; functiongrabble () {se...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.