Heres a small function i made that connections to the download section of php.net with fopen and gets the latest versions of the source and binary downloads of php as links. The function returns the data as an multi-dimensional array, the binary data is in $var['binary], while the source data is in $var['source']. The links are stored in numerical order in them like:
$var['source'][0]
would be the first source link.
I hope people find it useful, also I repeat, this isnt a hack, but if this isnt allowed or is in a wrong forum can a mod please delete/move it, thank you.
Also ill post an demo screen shot below.
PHP Code:
function latest_versions() {
if ($filenum=@fopen("http://www.php.net/downloads.php","r")) {
$contents="";
while (!@feof($filenum)) {
$contents.=@fread($filenum,1024);
}
@fclose($filenum);
$lines = explode("\n",$contents);
unset($source);
unset($binary);
unset($phpversion);
for($i=0;$i<count($lines);$i++) {
if (trim($lines[$i]) == "<h2>Complete Source Code</h2>")
$source = true;
if (trim($lines[$i]) == "<h2>Windows Binaries</h2>")
$binary = true;
if ($source or $binary) {
if (substr(trim($lines[$i]),0,strlen("<li><a href=\"/get_download.php?df=")) == "<li><a href=\"/get_download.php?df=") {
$line = ereg_replace("<li>","",$lines[$i]);
$line = ereg_replace("<br />","",$line);
$line = ereg_replace("/get_download.php","http://www.php.net/downloads.php",$line);
$line = ereg_replace('">','" target="_blank">',$line);
$line = explode("</a>",$line);
if ($source) {
$phpversion['source'][] = trim($line[0])."</a>";
} else if ($binary) {
$phpversion['binary'][] = trim($line[0])."</a>";
}
}
if ($source) {
if (substr(trim($lines[$i]),0,strlen("</ul>")) == "</ul>")
unset($source);
} else if ($binary) {
if (substr(trim($lines[$i]),0,strlen("</ul>")) == "</ul>") {
unset($binary);
return $phpversion;
}
}
}
}
return $phpversion;
}
return false;
}
Heres an example on how to use it:
PHP Code:
<?
function latest_versions() {
if ($filenum=@fopen("http://www.php.net/downloads.php","r")) {
$contents="";
while (!@feof($filenum)) {
$contents.=@fread($filenum,1024);
}
@fclose($filenum);
$lines = explode("\n",$contents);
unset($source);
unset($binary);
unset($phpversion);
for($i=0;$i<count($lines);$i++) {
if (trim($lines[$i]) == "<h2>Complete Source Code</h2>")
$source = true;
if (trim($lines[$i]) == "<h2>Windows Binaries</h2>")
$binary = true;
if ($source or $binary) {
if (substr(trim($lines[$i]),0,strlen("<li><a href=\"/get_download.php?df=")) == "<li><a href=\"/get_download.php?df=") {
$line = ereg_replace("<li>","",$lines[$i]);
$line = ereg_replace("<br />","",$line);
$line = ereg_replace("/get_download.php","http://www.php.net/downloads.php",$line);
$line = ereg_replace('">','" target="_blank">',$line);
$line = explode("</a>",$line);
if ($source) {
$phpversion['source'][] = trim($line[0])."</a>";
} else if ($binary) {
$phpversion['binary'][] = trim($line[0])."</a>";
}
}
if ($source) {
if (substr(trim($lines[$i]),0,strlen("</ul>")) == "</ul>")
unset($source);
} else if ($binary) {
if (substr(trim($lines[$i]),0,strlen("</ul>")) == "</ul>") {
unset($binary);
return $phpversion;
}
}
}
}
return $phpversion;
}
return false;
}
$phpversion = latest_versions();
echo "<b>Latest Php Version (source):</b><br>\r\n";
for ($i=0;$i<count($phpversion['source']);$i++) {
$source_version = $phpversion['source'][$i];
echo "$source_version<br>\r\n";
}
echo "<b>Latest Php Version (binary):</b><br>\r\n";
for ($i=0;$i<count($phpversion['binary']);$i++) {
$binary_version = $phpversion['binary'][$i];
echo "$binary_version<br>\r\n";
}
echo "<p><pre>".print_r($phpversion).</pre></p>";
?>