0

我有这个代码示例(由其他人编写),它解析网站,找到每种文件类型(beta/developmental/release)的最新版本的 URL 并返回它们。

我希望能够执行 bukkit.php?version=beta 之类的操作,并让它自动转到该 URL 并开始下载。我将如何去做这种性质的事情?

<?php

require_once('simple_html_dom.php');

$html = file_get_html('http://dl.bukkit.org/downloads/craftbukkit/');

$dom = new DOMDocument;
libxml_use_internal_errors(true);
echo $dom->loadHTML($html) ? "success<br/>" : "failed<br/>";
libxml_clear_errors();
$dom->preserveWhiteSpace = true;


foreach ($dom->getElementsByTagName('div') as $element){
    if($element->getAttribute('class') == "innerContent"){
        foreach ($element->getElementsByTagName('a') as $link) {
            if( $link->getAttribute('class') == "tooltipd")
            {
                echo $link->getAttribute('href')."<br/>";
            }
        }
    }
}

?>
4

2 回答 2

0

而是使用正则表达式来查找 url

$html = file_get_html('http://dl.bukkit.org/downloads/craftbukkit/');
preg_match("/bukkit\.php\?version=([beta|alpha|rc]+)/i", $html, $matches);
header("Location: ". $match[1]);
于 2012-03-09T12:44:57.643 回答
-1

像这样的东西可能是您正在寻找的东西:

$version = $_GET['version'];
if($version == 1) {
    header("Location: http://www.domain.com/version1"); 
} else if($version == 2) {
    header("Location: http://www.domain.com/version2"); 
} 
于 2012-03-09T12:34:50.217 回答