我有这个网址
http://www.mywebsite.com/person?id=10
但我不想要$_GET
变量。
我想这样:
http://www.mywebsite.com/person/10
答案 0 :(得分:0)
你可以使用$ _SERVER ['REQUEST_URI'] 你可以从“人”中爆炸(如果这将被解决)
#include <cstdio>
#include <stdexcept>
#include <system_error>
#include <string>
class MyException : public std::system_error {
public:
MyException(int errorValue, std::error_category const& category)
: std::system_error(
errorValue, category,
"MyException: " + std::to_string(errorValue)
)
{ }
};
int main() {
std::runtime_error ex;
try {
throw MyException(4, system_category());
} catch(MyException const& e) {
ex = e;
}
std::printf("what= %s", ex.what());
}
答案 1 :(得分:0)
下面是一个方便的小功能,您可以在这种情况下使用。您可能想要测试代码here。
<?php
$currentURL = getCurrentPageURL(); //<= GET THE ACTIVE PAGE URL
$cleanURL = getPreFormattedURI($currentURL);
var_dump($cleanURL);
// FUNCTION TO AUTOMATICALLY GET THE ACTIVE PAGE URL
function getCurrentPageURL() {
$pageURL = 'http';
if ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == "on")) {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"];
}else {
$pageURL .= $_SERVER["SERVER_NAME"];
}
$pageURL .= $_SERVER["REQUEST_URI"];
return $pageURL;
}
// FUNCTION THAT FORMATS THE URL THE WAY YOU SPECIFIED
function getPreFormattedURI($uri, $key="id"){
$objStripped = new stdClass();
$objParsedQuery = new stdClass();
if(!stristr($uri, "?")){
$objStripped->M = $uri;
$objStripped->Q = null;
}else{
$arrSplit = preg_split("#\?#", $uri);
$objStripped->M = $arrSplit[0];
$objStripped->Q = $arrSplit[1];
}
$cleanURL = $objStripped->M;
if($objStripped->Q){
$arrSplit = preg_split("#[\?\&]#", $objStripped->Q);
if(!empty($arrSplit) && count($arrSplit)>0 ) {
foreach ($arrSplit as $queryKVPair) {
preg_match("#(.*)(\=)(.*)#", $queryKVPair, $matches);
list($fullNull, $key, $null, $value) = $matches;
$objParsedQuery->$key = $value;
$cleanURL .= "/" . $value;
}
}
$objStripped->Q = $objParsedQuery;
}
return $cleanURL;
}