Here, use mine...
This takes http://www.site.com/var_value/var2_value2/...
and turns it to constants with their variable names uppercased.
echo VAR;
echo VAR2
you can test for constants:
if (@constant('var') {
// do something
}
but it doesn't work at all like what you were referencing. Perhaps you could modify it to work that way, but I don't see the point really.
Anyway, check it out, I ripped these functions from my actual varMan class to make this one real quick, it should work though.... or atleast give you a rough idea of how to go about it.
<? class vars() {
function getPathVals($URI) {
$URL = parse_url($URI);
$Path = explode("/", $URL['path']);
if (defined('DEBUG_ALL')) {
foreach ($URL as $key => $val) {
echo ('Writing Path info: ' . $key . ' ' . $val);
}
}
Path[1] instance will now be callable as 'LOCATION'
define('LOCATION',$Path[1]);
FOR ($i=2;$i<count($Path)-1;$i++) {
$break = $Path[$i];
$inputs = explode("_", $break);
$pathArr[$inputs[0]] = $inputs[1];
$this->vars2constant($pathArr);
}
if (array_key_exists('query',$URL)) {
$qArr = explode('&',$URL['query']);
for ($i=0;$i<count($qArr);$i++) {
$qVars = explode('=',$qArr[$i]);
define(strtoupper($qVars[0]),$qVars[1]);
}
}
}
function vars2constant($vars) {
// loop through array and define all elements as constant from keys //
foreach($vars as $key=>$val) {
if (is_array($vars[$key])) {
foreach ($vars[$key] as $nKey=>$nVal) {
if (!is_array($nVal)) {
if (!@constant($nKey) && strlen($nVal)>0) {
define($nKey, $this->bless($nVal) );
}
}
}
} else {
if (strlen($val)>0) { define( $this->bless($key), $this->bless($val) ); }
}
}
}
function bless($heathen_var) {
$blessed_var = addcslashes( $heathen_var, "\0..\37!\177..\377" );
return $blessed_var;
}
function unbless($blessed_var) {
$heathen_var = stripcslashes( $blessed_var );
return $heathen_var;
}
} //end class
?>