Number of External Links in a page

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.

public function getExternalLinks( $page_content, $domain ){
  // Get the urls
  $urls = UrlTools::get_urls( $page_content, $domain );
  // preg match links with domain, domain =
  $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