$site
=
substr
(
$url
,0,
strpos
(
$url
,
"/"
,8));
$base
=
substr
(
$url
,0,
strrpos
(
$url
,
"/"
)+1);
$fp
=
fopen
(
$url
,
"r"
);
while
(!
feof
(
$fp
))
$contents
.=
fread
(
$fp
,1024);
$pattern
=
"|href=['"
]?([^ '
"]+)['"
]|u";
preg_match_all(
$pattern
,
$contents
,
$regarr
, preg_set_order);
for
(
$i
=0;
$i
<
count
(
$regarr
);
$i
++){
if
(!
eregi
(
"://"
,
$regarr
[
$i
][1]))//是否是相对路径,即是否还有://
if
(
substr
(
$regarr
[
$i
][1],0,1)==
"/"
)
echo
"link"
.(
$i
+1).
":"
.
$site
.
$regarr
[
$i
][1]."
";
else
echo
"link"
.(
$i
+1).
":"
.
$base
.
$regarr
[
$i
][1]."
";
else
echo
"link"
.(
$i
+1).
":"
.
$regarr
[
$i
][1]."
";
}
fclose(
$fp
);