我们为大家详细介绍了有关
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("/imgs+[^>]*s*srcs*=
s*(['"]?)([^'">s]*)\1s*[^>]*>/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;$icount($_link);$i++){
-
$s .= "
" . "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.调用实例:
<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ?php </span></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>
</li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol><br>
ログイン後にコピー
以上就是PHP搜索引擎类的相关使用方法。