Hi G-Net,
Regexes get very complex, very quick! They are fantastic, but to do useful searches/replaces it's a steep learning curve.
Using string/array methods is much, much easier, so why not simplify the problem as much as possible before using regexes.
Something like ...
<?php
function getArgs($url){
$parts = explode('?', $url);
if(count($parts) == 1){
return false;
} else if(count($parts) != 2){
die('More than one ? in $url');
}
// If we've made it here then $parts is an array of
// the form array(string filepath, string arguments)
$argstrings = explode('&', $parts[1]);
// $argstrings is an array of parameters of the form
// array('name1=value1', 'name2=value2', ...)
// Or, in your case ... array('name1', 'name2', ...)
$args = array();
foreach($argstrings as $item){
$parts = explode('=', $item);
if(count($parts) == 1){
// Means there's no '=' (like your example urls)
$args[$parts[0]] = false;
} else {
// The usual case ('name1=value1')
$args[$parts[0]] = $parts[1];
}
}
// Now return the $args hash
return $args;
}
$urls = array(
'http://www.arh.domain.com/cgi-bin/f...i?abc&abdc1'
, 'http://www.crh.domain.com/cgi-bin/f...i?def&defg3'
, 'http://www.erh.domain.com/cgi-bin/f...i?apo2&nbg1'
, 'http://www.prh.domain.com/cgi-bin/file.cgi?rew&zzz9'
);
// Try it
foreach($urls as $url){
$args = getArgs($url);
// In your case you could just get the keys of $args instead of using the hash
$keys = array_keys($args);
echo '<strong>'.$url.'</strong><pre>'; print_r($keys); echo '</pre>';
}
?>
Hope that helps!
Paul.