Some tips for your code cwarn:
Don't use preg_* functions unless absolutely necessary, if you're comparing a static string use strpos or stripos.
Define reused regular expressions in one place (you use
/(.*)[.]([^.\?]+)(\?(.*))?/ three times in the same script, define it once in a variable and use it that way, one point of failure is always better.
If you're going to go for speed at the cost of memory usage get rid of in_array. Build an 1-level index and use isset() so you're performing O(1) operations instead of O(n) the in_array and array_key_exists functions are expensive. Example:
$some_big_array = array(1 => somestring, ..., 10000 => anotherstring);
$strings_index = array('somestring' => 1, ...., 'anotherstring' => 1);
$search = 'somestring';
if (isset($strings_index[$search])) // O(1) operation
if (in_array($search, $some_big_array)) // O(n) operation
STOP USING
global
Don't use unset() right before an assignment of the same variable, ie.,
$datac = "somestring";unset($datac);$datac = "anotherstring";
The unset becomes wasted time because reassignment is an implicit flush of previous memory