显示目标网页中的的联接地址
时间:2007-02-17 来源:PHP爱好者
来源:奥索网
<?
// _______________________________________
// title: 一个代码片断,显示目标网页中的
// <A><IMG>的联接地址
// date: 2000年10月9日
// create by:sfs([email protected])
// homepage:fire.oso.com.cn
// _______________________________________
?>
<html>
<title></title>
<body>
<?
function explorer($line,$tag,$baseurl){
$lastchar = strrpos($baseurl,"/");
$baseurl = substr($baseurl , 0 , $lastchar + 1);
$tok = strtok(substr($line,1,-1)," ");
$i=0;
while($tok){
$para[$i] = $tok;
$i=$i+1;
$tok = strtok(" ");}
for($j=1;$j<$i;$j++){
$tok = $para[$j];
$paraName = trim(strtok($tok,"="));
$paraValue = strtok("");
$paraValue = strtr($paraValue , "’" , " ");
$paraValue = strtr($paraValue , ’"’ , " ");
$paraValue = trim($paraValue);
switch($tag){
case "A";
if (strtoupper($paraName)=="HREF"){
echo "a : $paraValue
";
}
break;
case "IMG";
if (strtoupper($paraName)=="SRC"){
echo "img : $paraValue
";
;}
break;
case "FRAME";
if (strtoupper($paraName)=="NAME"){
echo "frame ______ $paraValue ______
";
};
if (strtoupper($paraName)=="SRC"){
web($baseurl.$paraValue);
;}
}
}
}
function web($url){
$imgs = ’<font color="red">’;
$imge = ’</font>’;
$as = ’<font color="blue">’;
$ae = ’</font>’;
$frames =’<font color="green">’;
$framee = ’</font>’;
$fp = fopen($url,"r");
if(!$fp) {
} else {
$ctold = "|";
while(!feof($fp)) {
$ct = fgets($fp,1);
if($ct=="<"){
$bool=TRUE;
$ht="";
}
if($bool && (ord($ct) > 31) ) {
if ($ct==" ")
{ if( ($ct!==$ctold ))$ht=$ht.$ct;}
else $ht=$ht.$ct;
$ctold = $ct;
}
if($ct==">"){
$bool=FALSE;
$ht = ltrim($ht);
if(eregi("<*a ",$ht)){
echo $as.htmlspecialchars($ht).$ae."
n";
explorer($ht,"A",$url);
}
else
if(eregi("<*img ",$ht)){
echo $imgs.htmlspecialchars($ht).$imge."
n";
explorer($ht,"IMG",$url);
}
else
if(eregi("<*frame ",$ht)){
echo $frames.htmlspecialchars($ht).$framee."
n";
explorer($ht,"FRAME",$url);
}
}
}
fclose($fp);
}
}
$openurl= ’http://www.yahoo.com’;
web($openurl);
?>
</body>
</html>
php爱好 者站 http://www.phpfans.net php基础|php进阶|php模板.
<?
// _______________________________________
// title: 一个代码片断,显示目标网页中的
// <A><IMG>的联接地址
// date: 2000年10月9日
// create by:sfs([email protected])
// homepage:fire.oso.com.cn
// _______________________________________
?>
<html>
<title></title>
<body>
<?
function explorer($line,$tag,$baseurl){
$lastchar = strrpos($baseurl,"/");
$baseurl = substr($baseurl , 0 , $lastchar + 1);
$tok = strtok(substr($line,1,-1)," ");
$i=0;
while($tok){
$para[$i] = $tok;
$i=$i+1;
$tok = strtok(" ");}
for($j=1;$j<$i;$j++){
$tok = $para[$j];
$paraName = trim(strtok($tok,"="));
$paraValue = strtok("");
$paraValue = strtr($paraValue , "’" , " ");
$paraValue = strtr($paraValue , ’"’ , " ");
$paraValue = trim($paraValue);
switch($tag){
case "A";
if (strtoupper($paraName)=="HREF"){
echo "a : $paraValue
";
}
break;
case "IMG";
if (strtoupper($paraName)=="SRC"){
echo "img : $paraValue
";
;}
break;
case "FRAME";
if (strtoupper($paraName)=="NAME"){
echo "frame ______ $paraValue ______
";
};
if (strtoupper($paraName)=="SRC"){
web($baseurl.$paraValue);
;}
}
}
}
function web($url){
$imgs = ’<font color="red">’;
$imge = ’</font>’;
$as = ’<font color="blue">’;
$ae = ’</font>’;
$frames =’<font color="green">’;
$framee = ’</font>’;
$fp = fopen($url,"r");
if(!$fp) {
} else {
$ctold = "|";
while(!feof($fp)) {
$ct = fgets($fp,1);
if($ct=="<"){
$bool=TRUE;
$ht="";
}
if($bool && (ord($ct) > 31) ) {
if ($ct==" ")
{ if( ($ct!==$ctold ))$ht=$ht.$ct;}
else $ht=$ht.$ct;
$ctold = $ct;
}
if($ct==">"){
$bool=FALSE;
$ht = ltrim($ht);
if(eregi("<*a ",$ht)){
echo $as.htmlspecialchars($ht).$ae."
n";
explorer($ht,"A",$url);
}
else
if(eregi("<*img ",$ht)){
echo $imgs.htmlspecialchars($ht).$imge."
n";
explorer($ht,"IMG",$url);
}
else
if(eregi("<*frame ",$ht)){
echo $frames.htmlspecialchars($ht).$framee."
n";
explorer($ht,"FRAME",$url);
}
}
}
fclose($fp);
}
}
$openurl= ’http://www.yahoo.com’;
web($openurl);
?>
</body>
</html>
php爱好 者站 http://www.phpfans.net php基础|php进阶|php模板.
相关阅读 更多 +