Forum Moderators: coopster
// option 1, tested and works but it's the slowest to process
// surprisingly, this is marginally faster without in_array()
if (in_array(false, $_GET, true)) {
if (preg_match('/(?:^|&)name=(\w+&\w+)(?:&|$)/', $_SERVER['QUERY_STRING'], $matches))
$_GET['name'] = $matches[1];
}
// option 2, tests faster and allows for multiple &, but it doesn't guarantee that they're inline so
// it would convert "$name=foo&lorem=ipsum&bar" to "$name=foo&bar"
if (in_array(false, $_GET, true)) {
foreach ($_GET as $key => $val) {
if (!$val) {
$_GET['name'] = $_GET['name'] . '&' . $key;
unset($_GET[$key]);
}
}
}
if (in_array(false, $_GET, true)) {
RewriteCond name=(\w+)&(\w+)(?:&|$) [NC]
RewriteRule ^ ${'SCRIPT_NAME'}?name=%1\%26%2 [QSA,NC,L] Code readability and reliability are the only factors here. You've already demonstrated that the second one is functionally incorrect, so why go with that?
Not sure why you are calling this as an initial check?
My logic was to see if there are any $_GET keys with a false value, which I think would only be true if there's a &bar key set with no value. If this is false then there's no need to move on to the loop. Is that logic wrong?
It made it process marginally faster
I'm totally open to fixing it in Apache...
And I feel like I've read that if you have to use a regex then you've already lost? Or something like that... LOL
That's why I was using STRICT in in_array...
if (in_array(false, $_GET) &&
preg_match('/(?:^|&)name=(\w+&(\w+))(?:&|$)/', $_SERVER['QUERY_STRING'], $matches)) {
$_GET['name'] = $matches[1];
unset($_GET[$matches[2]]);
}