<?
$URL = "http://www.zwon.net/"; //start HTML page
print("<HTML>\n");
print("<HEAD>\n");
print("<TITLE>取得页面的链接</TITLE>\n");
print("</HEAD>\n");
print("<BODY>\n"); $page = fopen($URL, "r");//打开URL print("链接 $URL<BR>\n");
print("<UL>\n"); while(!feof($page))//在页面中循环
{
$line = fgets($page, 255);
while(eregi("HREF=\"[^\"]*\"", $line, $match))
{
//打印出URL链接
print("<Li>");
print($match[0]);
print("<BR>\n");
}
} print("</UL>\n"); fclose($page); //关闭页面
print("</BODY>\n");
print("</HTML>\n");
?>
$URL = "http://www.zwon.net/"; //start HTML page
print("<HTML>\n");
print("<HEAD>\n");
print("<TITLE>取得页面的链接</TITLE>\n");
print("</HEAD>\n");
print("<BODY>\n"); $page = fopen($URL, "r");//打开URL print("链接 $URL<BR>\n");
print("<UL>\n"); while(!feof($page))//在页面中循环
{
$line = fgets($page, 255);
while(eregi("HREF=\"[^\"]*\"", $line, $match))
{
//打印出URL链接
print("<Li>");
print($match[0]);
print("<BR>\n");
}
} print("</UL>\n"); fclose($page); //关闭页面
print("</BODY>\n");
print("</HTML>\n");
?>
$URL = "http://www.zwon.net/"; //start HTML page
print("<HTML>\n");
print("<HEAD>\n");
print("<TITLE>取得页面的链接</TITLE>\n");
print("</HEAD>\n");
print("<BODY>\n"); $page = fopen($URL, "r");//打开URL print("链接 $URL<BR>\n");
print("<UL>\n"); while(!feof($page))//在页面中循环
{
$line = fgets($page, 255);
while(eregi("HREF=\"[^\"]*\"", $line, $match))
{
//打印出URL链接
print("<Li>");
print($match[0]);
print("<BR>\n");
}
} print("</UL>\n"); fclose($page); //关闭页面
print("</BODY>\n");
print("</HTML>\n");
?>
<a href=XXX>YYYY</a>把XXX与YYY都取出来
$f=file('http://www.sohu.com/index.html');
$str="";
while(list($line_num,$line)=each($f))
{
$str.=$line;
}
$count=0;
$ptn="@(.*?)<a\s([^>]*?)href=([\'\"\s]?)([^>\'\"\s]+)([\'\"\s]?)([^>]*?)>(.+?)</a>(.*)@is";
while(preg_match($ptn,$str,$reg))
{
echo "-----------------------------------------------------------------------------------";
$count++;
echo "〖".$reg[4]."〗<br>";
echo $count."【".$reg[7]."】<br>";
$str=$reg[1].$reg[8];
}
?>
/**
* 从一个HTML代码中取出所有的链接
*
* @access public/pravite
* @param string
* @return void
*/
function RexFindLink($str) {
$str = str_replace ("<a ", "{#mya}", $str);
$str = str_replace ("</a>", "{#@mya}", $str);
$str = str_replace ("<A ", "{#mya}", $str);
$str = str_replace ("</A>", "{#@mya}", $str);
$str = strip_tags($str);
$str = str_replace ( "{#mya}", "<a ",$str);
$str = str_replace ( "{#@mya}", "</a>",$str);
$ptn="@(.*?)<a\s([^>]*?)href=([\'\"\s]?)([^>\'\"\s]+)([\'\"\s]?)([^>]*?)>(.+?)</a>(.*)@is";
while(preg_match($ptn,$str,$reg)){
$str=$reg[1].$reg[8];
$result1[] = $reg[7];
$result2[] = $reg[4]; }
Return array($result1,$result2);
}
链接 http://yep/temp/top.phphref="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"href="style.css"
-----------------------------------------------------------------------------------〖http://register.mail.sohu.com/reg/Reg1.jsp〗
1【注册免费邮件】
-----------------------------------------------------------------------------------〖http://mail.sohu.net/〗
2【企业邮箱】
-----------------------------------------------------------------------------------〖http://host.sohu.net/〗
3【域名虚机】
-----------------------------------------------------------------------------------〖http://sh.sohu.com/〗
4【上海站】
-----------------------------------------------------------------------------------〖http://gd.sohu.com/〗
5【广东站】
-----------------------------------------------------------------------------------〖http://www.sohu.com/〗
6【首页】
-----------------------------------------------------------------------------------〖http://sms.sohu.com/〗
7【短信】
-----------------------------------------------------------------------------------〖http://mms.sohu.com〗
8【彩信】
-----------------------------------------------------------------------------------〖http://login.mail.sohu.com/〗
9【邮件】
-----------------------------------------------------------------------------------〖http://alumni.sohu.com/〗
10【校友录】
-----------------------------------------------------------------------------------〖http://dir.sohu.com/〗
11【搜索】
-----------------------------------------------------------------------------------〖http://store.sohu.com/〗
$song='01.Because You\'re
Good To Me </TD>
<TD class=unnamed2 align=middle width="9%" height=12><A
href="ftp://ftp.jl.cninfo.net/pub/mp3/eason/0401.mp3"><FONT
color=#000000>下载</FONT></A></TD>
<TD class=unnamed2 align=middle width="9%" height=12><A
href="http://music.jl.cninfo.net/newzj/eason/04/01.rm"><FONT
color=black>试听</FONT></A></TD></TR>
<TR>';
$patt="@<a\s([^>]*?)href=([\'\"\s]?)([^>\'\"\s]+)([\'\"\s]?)([^>]*?)>(.+?)</a>@is";
while(preg_match($patt,$song,$reg)){
echo $reg[3];
}
?>
这个为什么会死循环呀??
请高手做答。