Php 如何基于查询字符串返回值?

Php 如何基于查询字符串返回值?,php,parsing,query-string,simple-html-dom,url-parameters,Php,Parsing,Query String,Simple Html Dom,Url Parameters,我有这个代码示例(由其他人编写),它解析网站,找到每种类型文件(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/'

我有这个代码示例(由其他人编写),它解析网站,找到每种类型文件(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/>";
            }
        }
    }
}

?>
loadHTML($html)?“success
”:“failed
”; libxml_clear_errors(); $dom->preserveWhiteSpace=true; foreach($dom->getElementsByTagName('div')作为$element){ 如果($element->getAttribute('class')==“innerContent”){ foreach($element->getElementsByTagName('a')作为$link){ 如果($link->getAttribute('class')==“tooltipd”) { echo$link->getAttribute('href')。“
”; } } } } ?>
像这样的东西可能就是你想要的:

$version = $_GET['version'];
if($version == 1) {
    header("Location: http://www.domain.com/version1"); 
} else if($version == 2) {
    header("Location: http://www.domain.com/version2"); 
} 

而是使用正则表达式来查找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]);