I've been trying to figure this one out for some time. I'm using a rather hacked to death version of a script I found on cputils.com to show disk usage for all accounts on a WebHost Manager list that I intend to use within a backup schedule script. It uses the preg_match_all expression, construct, command, not sure really, anyway here's the code if somebody can give me a hint as to why mine isnt working :quiet:
This is my code:
//get WHM list accounts
$page2 = @file_get_contents("http://$whmUser:$whmPass@$url:2086/scripts2/listaccts?viewall=1");
//get each account table row
$match2 = preg_match_all("|<[tr class=\"tdshade2\"]>(.*?)<[/tr]>|U", $page2, $match);
if(isset($match2)) {
foreach($match as $stuff => $match3) {
$account = explode('</td><td>',$stuff);
$msg .= "<br>".'Domain: '.strip_tags($account[0]).'<br>'.' -- Space used: '.$account[54]."\n";
echo $msg;
}
echo "<br>"."True but loop not working...";
}
else {
$msg .= "\n<br>Error<br>\n";
echo $msg;
}
Now the original:
$page2 = @file_get_contents("https://$whmUser:$whmPass@$url:2087/scripts2/listaccts?viewall=1");
//get each accounts table row
$int2 = preg_match_all("/<tr class=(?:tdshade2|tdshade1)>(.*?)<\/tr>/is", $page2, $matches);
if($int2 > 0 && is_array($matches[1])) {
foreach($matches[1] as $match) {
$account = explode('</td><td>',$match);
$msg .= 'Domain: '.strip_tags($account[0]).' -- Space used: '.$account[7]."\n";
$clientTotal += $account[7];
}
$total = ceil($clientTotal + $resellerTotal[1]);
$msg .= 'Total space used: '.$total." mb \n";
$remaining = ceil($resellerQuota - $total);
$msg .= 'Remaining space: '.$remaining." mb \n";
}
else {
$msg .= "No workee.\n";
}
Here is something a friend did get to work however:
$page = @file_get_contents('http://$whmUser:$whmPass@$url:2086/scripts2/listaccts?viewall=1','r');
$int = preg_match_all("|<[>]+>(.*)</[>]+>|U", $page, $match);
if(isset ($int)) {
foreach($match as $stuff => $matches){
$match[$stuff] = strip_tags($match[$stuff]);
echo "<HR>";
echo $match[$stuff];
echo "<HR>";
print_r($match);
echo "<HR>".$page;
}
}
else {
echo 'no data';
}
So the hacked up version (mine) of his code doesnt seem to work either and I'm guessing the reason the friend's works is because it searches for anything correct? I've looked through php.net's man pages on preg_match and preg_match_all. I'm guessing the problem must lie in the string I am searching for or how I am formatting the search, maybe his code was deprecated to begin with? I've only about 2 months experience with PHP, so if anybody can help, please be gentle