You just need to first extract the urls out of each file, parse them for the query string, and then use the function parse_str to parse the query string into an array to get it's values. Then reconstruct the url with your new query string and do a str_replace of the old url with the new one you have created.
Search the PHP sites and you will find the regex that returns all the urls, in this code I will reference it as function "getAllHrefs()".
$contents = join("",file($your_file));
$orig_urls = getAllHrefs($contents);
foreach($orig_urls as $old_url)
{
$url_parts = parse_url($old_url);
if(strlen($url_parts["query"]) > 0)
{
parse_str($url_parts["query"], $values);
// $values now contains the values for
// the url you are working with. You
// can use them in database queries etc
// e.g. $values["wkn"] will return 123456
// from the url above.
// Do your database stuff and build your new
// query string.
$new_url = "http://your_server.com/".$url_parts["path"]."?".$your_new_query_str;
$contents = str_replace($old_url, $new_url, $contents);
}
}
$fp = fopen($your_file,"w");
fwrite($fp, $contents);
fclose($fp);
Good luck!
Jack