php 正则表达式获取网页所有网址和链接文字

  1. $url ='http://www.phpfensi.com';
  2. $body=@file_get_contents($url);
  3. preg_match_all('/href=['"]?([^'"]*)['"]?>(.*)/i',$body,$b);
  4. $nums = array();
  5. foreach($b[1] as $u){
  6. if(in_array($u,$nums)){
  7. continue;
  8. }
  9. $nums[]=$u;
  10. $title=strip_tags($u);
  11. echo $title."</br>";
  12. }