利用正则提取所有的a标签,将链接地址(www.csdn.net)与内容(中国程序网)生成一个键与值对应的数组.比如$aArray['www.csdn.net'] = '中国程序网'。找的时候就很简单了。

解决方案 »

  1.   

    我这样找A标签可以吧?  <a href=(.*?)>(.*)<\/a>/si
      

  2.   

    function getValue($str, $start, $end, $start_num=1, $end_num=1)
    {
    if(empty($str))return "";
    if(empty($start))return "";
    if(empty($end))return "";
    $pos1 = 0;
    for($i=0; $i<$start_num; $i++)
    {
    $pos1 = strpos($str, $start, $pos1);
    if($pos1===false)
    {
    return "";
    }
    $pos1 = $pos1 + strlen($start);
    }
    $pos2 = $pos1;
    for($i=0; $i<$end_num; $i++)
    {
    $pos2 = strpos($str, $end, $pos2 + 1);
    if($pos2===false)
    {
    return "";
    }
    }
    return substr($str, $pos1, $pos2 - $pos1);
    }
    $data = '<a href="http://www.csdn.net" target="_blank">中国程序员网</a><a href="http://www.msdn.com" target="_blank">外国程序员网</a><a href="http://www.mistruster.com" target="_blank">Mistruster</a>...';
    echo getValue($data, '<a href="', '"');
    echo "<br>\n";
    echo getValue($data, '<a href="', '"', 2);
    echo "<br>\n";
    echo getValue($data, '<a href="', '"', 3);
    //...
      

  3.   

    最快最准的还是正则VBScript正则<a href=(.*?) .*?>(.*?)<\a>循环\1和\2