This seems to work:
<?php
$testData = <<<EOD
<p>content here <a href="http://www.somewhere.com/">link</a></p>
<p>content here <a href="http://www.somewhere.com/?var=1">link</a></p>
EOD;
$search = array(
'/<a\s[^>]*href=[^\s>]+\?[^\s>\'"]+(?=\'|"|\s|>)/i',
'/<a\s[^>]*href=[^\s>\?][^\s>\?\'"]+(?=\'|"|\s|>)/i',
);
$replace = array(
'\\0&id=100',
'\\0?id=100'
);
$output = preg_replace($search, $replace, $testData);
printf("<pre>%s</pre>", htmlspecialchars($output));
?>