<?
require_once('inc/conn.php');
$opendb=new mydb();
require_once('inc/char_set.php');

include_once("inc/simple_html_dom.php"); //加载simple_html_dom.php文件
$html=file_get_html('../index.html');//获取html 
$dom=new simple_html_dom();//new simple_html_dom对象 
$dom->load($html); //加载html 


//Find all links
foreach($dom->find('a') as $element){ //获取a标签的数组
	/*
	echo $element->href.'<br>';//获取每个a标签中的href
	echo $element->innertext.'<br>';
	*/	
	$getTitle=$element->innertext;
	if(strpos($getTitle,"'") ===false && strpos($getTitle,'"') ===false)
	{
		$in_sql="SELECT * FROM ls_internal  where enable=1 and title='".$getTitle."' "; // 
		$in_query=$opendb->query($in_sql);
		$link_num=mysql_num_rows($in_query);
		 
		if($link_num!=0)
		{
			$link_rows=mysql_fetch_assoc($in_query);
			$getlink=$element->href;
			echo $getlink.'<br>';
			$wr_sql="update ls_internal set url='".$getlink."' where ID=".$link_rows['ID']." "; // 
			$opendb->query($wr_sql);
		
		}
		else  // 没有对应关键词就指到首页
		{
			$getlink="index.html";
			 
			$wr_sql="update ls_internal set url='".$getlink."' where ID=".$link_rows['ID']." "; //count the error by searchtype
			$opendb->query($wr_sql);
		}	
	}  
 
}
 
?>