实例讲解PHP搜索引擎类
我们为大家详细介绍了有关PHP搜索引擎类的一些使用方法,希望对大家有些帮助。下面我们先以一个范例来讲解类文件的概念。
PHP搜索引擎类1.类文件:
- class grabble{
- var $filename;
- var $html;
- var $urls = array(); //url历史
- var $url ;
- var $url_1;
- function grabble(){
- set_time_limit(3600);
- }
- function set($_filename){
- $this->filename = $_filename;
- array_push ($this->url, $_filename);
- }//end.set;
- function set_url($_url){
- eregi('(^http://.*[^/]).*' , $_url , $array);
- $this->url = $array[1] . "/";
- eregi('(^http://.*[^/]).*' , $_url , $array);
- //print_r($array);
- $this->url_1 = $array[1];
- }
- function get(){
- }//end.get;
- function get_html($_filename=null){
- $this->filename = $_filename;
- $this->html = @implode('', file($_filename)) ;
- return $this->html;
- }//end.get_html;
- function get_title($_str=null){
- preg_match_all("/<title>(.*)<\/title>
/Uis", $_str, $matches); - return $matches[1][0];
- }//end.get_title;
- function get_img($_str=null){
- preg_match_all("/<img\s+[^>]*\s*src\s*=
\s*([\'\"]?)([^\'\">\s]*)\\1\s*[^>]*>/i",
$_str, $arr); - print_r($arr[2]);
- }
- function get_link($_str=null){
- preg_match_all("/<a.*href=[\'|\"](.+)?
[\'|\"].*>.+<\/a>/Uis", $_str, $arr); - //print_r($arr);
- return $arr[1];
- }//end.get_link;
- function get_link_name($_str=null){
- preg_match_all("/<a.*href=[\'|\"](.+)?
[\'|\"].*>(.+)<\/a>/Uis", $_str, $arr); - return $arr[2];
- }//end.get_link_name;
- function link_list($_url=null, $_c=0){
- eregi('(^http://.*)/.*' , $_url , $array);
- $_url_0 = $array[1];
- $_html = $this->get_html($_url);
- $_link = $this->get_link($_html);
- $_list = $this->get_link_name($_html);
- $s = "";
- for($i=0;$i<count($_link);$i++){
- $s .= "<br/>" . "<INPUT TYPE='checkbox'
NAME='link_name[]' value='" .$_link[$i]. "'
/>" . $_list[$i] . " "; - echo "<br/>" . "<INPUT TYPE='checkbox'
NAME='link_name[]' value='" .$_link[$i]. "'
/>" . $_list[$i] . " "; - echo "<a href='" . $_url_0 . "/" . $_link[$i]
. "' target='_blank'>" . $_url_0 . "/" .
$_link[$i] . "</a>"; - if($_c < 3){
- if(eregi('^[$_url_0|mailto:].*' ,$_link[$i])){
- echo "<a href='" . $_link[$i] . "'
target='_blank'>" . $_link[$i] . "</a>"; - $s .= $this->link_list( $_link[$i] , $_c+1);
- }
- elseif(!eregi('^[http://|ftp://|file:///].
*' ,$_link[$i])){ - $s .= $this->link_list( $_url_0 . "/" . $_link[$i] , $_c+1);
- }
- }
- }
- return $s;
- }//end.link_list;
- }//end.grabble.
PHP搜索引擎类2.调用实例:
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20