PDA

View Full Version : This isnt a hack, just a function i made that gets the latest php versions.


Slynderdale
01-31-2003, 05:46 AM
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.


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:

<?
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>";
?>

Dean C
01-31-2003, 03:34 PM
Wow nice function :)

- miSt

Slynderdale
02-01-2003, 03:40 AM
Originally posted by Mist
Wow nice function :)

- miSt

Thanks, also if any of you were wondering, the version url's link to the main download page for php, not to the actual files, if you want it to link to the actual files, change this:


$line = ereg_replace("/get_download.php","http://www.php.net/downloads.php",$line);


to this:

$line = ereg_replace("/get_download.php","http://www.php.net/get_download.php",$line);