Number of External Links in a page
By Herve le turdu

It is sometimes interesting to know how many External links a page has.
Parsing the page Urls and taking away all those containing the domain name will give us an fair idea of the amount of External links.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public function getExternalLinks( $page_content, $domain ){
  // Get the urls
  $urls = UrlTools::get_urls( $page_content, $domain );
 
  // preg match links with domain, domain = auto123.com
  $pattern = '/'.$domain.'/';
 
  foreach($urls as $id=>$raw_url) {
    if(preg_match($pattern, $raw_url)) { $raw_url = '';} 
    if(empty($urls[$id])OR empty($raw_url)) { unset($urls[$id]); } //supprime les cases vides
    $externalLinks[] = $raw_url;
  }
  Return $externalLinks
}

The get_urls( $page_content, $domain ) should only return absolute urls.
Return $externalLinks returns all external urls. A count($externalLinks); should give the number of external links

Get the best prices on the web



RECENTLY BLOGGED ABT

TWEETS

  • My twitter:

Test of NS:

I will try to insert different elements into it:

Broken TWiTTs :(

  •  

AUTHOR

  • Hervé Le TurduMy name is Herve Le Turdu.
    I am a 32 years old french* man with an inquiring mind and an enthusiastic personality. Get to know me better !

    *Pardon my English tainted with a strong accent and of many mistakes

Projects & Work

LINKS - BeCause they deserve it!

I Love SEOgadget ----------------------------------------------------
Testing stuff:
http://leturdu.com/2010/03/number-of-external-links-in-a-page/

Test 1 // show post ID: 211

Test 2 // show category page: SEO