Use PHP to get the number of items for a domain on

Whilst working on my semi-automated SEO scan I wanted to get the number of listings for a given domain on some social bookmarking websites. Of course is a very well-known and widely-used bookmarking website but sadly they don’t offer a nice XML or JSON API to check the number of listings. That’s why I wrote the following code to retrieve this number.

function digg_bookmarks($domain)
	$html = $this->snoopy->snoopURL('' . $domain);
	$regexp = '/\<h2\>(\d+)\<span\>\<strong\>total\<\/strong\>/ismU';
	if (preg_match_all($regexp, $html, $matches)) {
		return $matches[1][0];
	} else {
		return 0;

In the code above I’ve used the great Snoopy class ( although somewhat edited ) but you could fall back on PHP’s own file_get_contents (or cURL). All you have to do is change line 3 to this.

	$html = file_get_contents('' . $domain);

You can now easily retrieve the number of listings by using the following function.

$number = digg_bookmarks('');
echo $number;

This will echo the number of dugg items for If no items have been found this function will return 0. As long as Digg doesn’t offer an API for this the code mentioned should work just fine, unless they dramatically change their lay-out.