(?(1) (.*?)\\1这段怎么理解呢?你的 preg_match_all("/ <\s*a.*href\s*=[\"\']?(\w*)[\"\']?.*>(\w*) <\/a\s*>/gi", $subject, $matches); 有错误,当文本是多行,很多链接时不行的 不过分也给你好了。这样才完美: preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href= ([\"\'])? # find single or double quote (?(1) (.*?)\\1 | ([^\s\>]+)).*?>(.*?)</a> # if quote found, match up to next matching # quote, otherwise match up to next space 'isx",$document,$links);
preg_match_all("/ <\s*a.*href\s*=[\"\']?(\w*)[\"\']?.*>(\w*) <\/a\s*>/gi", $subject, $matches);
有错误,当文本是多行,很多链接时不行的
不过分也给你好了。这样才完美:
preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href=
([\"\'])? # find single or double quote
(?(1) (.*?)\\1 | ([^\s\>]+)).*?>(.*?)</a> # if quote found, match up to next matching
# quote, otherwise match up to next space
'isx",$document,$links);
呵呵,那就多加个控制字符好了
"/****/gis"