通用HTML标准超链接参数取得正则表达式测试
因为最近要做一个类似专业搜索引擎的东西,需要抓取网页的所有超链接。
大家帮忙测试一下子,下面的代码是否可以针对所有的标准超链接。
测试代码如下:
<?php <BR>// -------------------------------------------------------------------------- <BR>// File name : Noname1.php <BR>// Description : 通用链接参数获取正则表达式测试 <BR>// Requirement : PHP4 (http://www.php.net) <BR>// Copyright(C), HonestQiao, 2005, All Rights Reserved. <BR>// Author: HonestQiao ([email protected]) <BR>// 参数说明: <BR>// $strSource: 包含标准链接的HTML网页 <BR>// $strResult: 处理的结果 <BR>// 附加说明: <BR>// 标准链接,使用形势包含的链接 <BR>// -------------------------------------------------------------------------- <BR>$strSource = <<<HTML <BR>t1 <BR>t2 <BR>t3 <BR>t4 <BR>HTML; <BR>preg_match_all('/(.+?)<\/a.*?>/sim', $strSource, $strResult, PREG_PATTERN_ORDER); <BR>for($i = 0; $i < count($strResult[1]);<mark style="color:transparent">本%文来源gaodaimacom搞#^代%!码网@</mark>搞代gaodaima码 $i++) <BR>{ <BR>printf("%d href=(%s) title=(%s) \n", $i, $strResult[1][$i], $strResult[2][$i]); <BR>} <BR>?> <BR>
如果您的测试数据,符合标准链接,但是此处没有被处理出来,请告诉我测试数据,以及你的测试环境。
谢谢。