If you have the fopen URL wrappers on in php.ini (see the manual here) the you can simply get the MailChimp number by doing:
$numSubscribers = file_get_contents("http://VoThink.us5.list-manage.com/subscriber-count?b=00&u=90da6513-a4c1-4189-be59-8de6f756b11e&id=2f5009734f");
If not, then you have to us something like [man]cURL[/man] or the Http PECL library. Using cURL is probably the most standard way to do this when allow_url_fopen is turned off.
To use cURL you have to first initialize a cURL object.
$ch = curl_init();
Then you need to set a few options on the cURL object. You need to tell it where it's going (CURLOPT_URL), and that you want to capture the response (CURLOPT_RETURNTRANSFER).
curl_setopt_array(
$ch,
array
(
CURLOPT_URL => "http://VoThink.us5.list-manage.com/subscriber-count?b=00&u=90da6513-a4c1-4189-be59-8de6f756b11e&id=2f5009734f",
CURLOPT_RETURNTRANSFER => true
)
);
Then it's just a matter of telling cURL to make the request you've configured and save the output to a variable, and then close the cURL resource.
$response = curl_exec($ch);
curl_close($ch);
The response from that URL above is actually javascript which adds a span tag to the DOM with the text node underneath it being the value you want. So you then need to parse out the value you want. You can do that easily with preg_match:
$matches = array();
preg_match("/document\.write\('.*>([0-9]+)<.*'\);/i", $response, $matches);
Once you've got that, $matches will hold two items:
-
The entire string matched
-
The first parenthesized group (the number of subscribers)
So at this point you can simply echo the second value in the $matches array ($matches[1]) or do the subtraction directly from it.
echo abs($matches[1] - 2000);
Here's the whole thing put together:
<?php
$ch = curl_init();
curl_setopt_array(
$ch,
array
(
CURLOPT_URL => "http://VoThink.us5.list-manage.com/subscriber-count?b=00&u=90da6513-a4c1-4189-be59-8de6f756b11e&id=2f5009734f",
CURLOPT_RETURNTRANSFER => true
)
);
$response = curl_exec($ch);
curl_close($ch);
$matches = array();
preg_match("/document\.write\('.*>([0-9]+)<.*'\);/i", $response, $matches);
echo "Number of Subscribers received: '" . $matches[1] . "'<br />";
echo abs($matches[1] - 2000);
?>
Hope that helps.