1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <html>
<head><body>gmbe.be ... en construction new index
<?php
define('DEF_myBasePath','/news');
function RemoveExtensionOrGetVar($valeur)
{
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' is the 0th (first) character.
$pos=strpos($valeur,'.');
if ($pos !== false)
{
$valeur=substr($valeur,0,$pos);
}
$pos=strpos($valeur,'?');
if ($pos !== false)
{
$valeur=substr($valeur,0,$pos);
}
return $valeur;
}
function RemoveBasePathFromRequestURI()
{
//PHP_SELF = /news/index.php
//REQUEST_URI = /news/europe/belgique/?blabla=truc&fdjdfs=dd
//this function must return /europe/belgique?blabla=truc&fdjdfs=dd
$beginPathToRemove="";
if(!defined('DEF_myBasePath'))
{
$pathindex= pathinfo($_SERVER["PHP_SELF"]);
$beginPathToRemove=$pathindex["dirname"];
}
else
{
$beginPathToRemove=DEF_myBasePath;
}
$pos=strpos($_SERVER["REQUEST_URI"],$beginPathToRemove);
if ($pos === false)
{
echo "<br/>error, returning REQUEST_URI<br/>";
return $_SERVER["REQUEST_URI"];
}
else
{
$returnstring=substr($_SERVER["REQUEST_URI"],strlen($beginPathToRemove));
return $returnstring;
}
}
function ExtractVarFromRequestUri()
{
$paramstring=RemoveBasePathFromRequestURI();
$pathvar= preg_split("/\//i", $paramstring, -1, PREG_SPLIT_NO_EMPTY);
foreach ($pathvar as $cle => $valeur)
{
$pathvar[$cle]=RemoveExtensionOrGetVar($valeur);
}
return $pathvar;
}
echo "<p>";
echo "PHP_SELF " . $_SERVER["PHP_SELF"];
echo "<br/>REQUEST_URI " . $_SERVER["REQUEST_URI"];
echo "<br/>QUERY_STRING " . $_SERVER["QUERY_STRING"];
echo "<br/>SCRIPT_FILENAME " . $_SERVER["SCRIPT_FILENAME"] . "</p>";
$pathvar3=ExtractVarFromRequestUri();
echo "<br/><br/>Fonction ExtractVar: <br/>";
print_r($pathvar3);
?>
</body>
</html> |
Partager