title: working with links : identifying external links and full address of links
body: <p>i'm trying to create a sitemap for my website 
  so basically i scan the homepage for links 
  and extract the links and do the same thing recursively for extracted links </p>
  
  <pre><code>  function get_contents($url = '' ) {
      if($url == '' ) { $url = $this-&gt;base_url; }
      $curl = new cURL;
      $content = $curl-&gt;get($url);
      $this-&gt;get_links($content);
   }
  
   public function get_links($contents){
  
                  $DOM = new DOMDocument();
                  $DOM-&gt;loadHTML($contents);
                  $a = $DOM-&gt;getElementsByTagName('a');
                  foreach($a as $link){
  
                       $h =  $link-&gt;getAttribute('href'); 
                       $l =  $this-&gt;base.'/'.$h;
                       $this-&gt;links[] = $l ;
                       $this-&gt;get_contents($l);
  
                  }
   }
  </code></pre>
  
  <p>it works fine but there are couple of problems </p>
  
  <p>1-</p>
  
  <p>i get some links ike </p>
  
  <pre><code>www.mysite.com/http://www.external.com
  </code></pre>
  
  <p>i can do something like </p>
  
  <pre><code>  if( stripos( $link  , 'http')  !== false
          ||
          stripos( $link  , 'www.')  !== false
          ||
          stripos( $link  , 'https') !== false
       )
      {
              if(stripos( $link  , 'mysite.com') !== false)
              {
                 //ignor this link (yeah i suck at regex and string mapping)
              }
      }
  </code></pre>
  
  <p>but it's seems very complicated and slow , is there any standard and clean way to find out if a link is a external link ?</p>
  
  <p>2 -</p>
  
  <p>is there any way to deal with relative paths ? 
  i get some thing like</p>
  
  <pre><code>www.mysite.com/../Domain/List3.html
  </code></pre>
  
  <p>obviusly this isn't right 
  i can remove (../) from link but it might not work with all links 
  is there anyway to find out full address of a link ? </p>