First, the dollar sign in regex is being interpolated by PHP because the regex is in double quotes. Put single quotes around that:
$html = preg_replace_callback('/\$[a-zA-Z_][a-zA-Z0-9_]*/', "find_replacements", $html);
Second, the values sent to your callback include the dollar sign, whereas the dollar sign is not present in the $allVars
array, so you must manually strip it off:
function find_replacements($match) {
global $allVars;
$match[0] = substr($match[0],1);
if (array_key_exists($match[0], $allVars))
return $allVars[$match[0]];
else
return $match[0];
}
Making those modifications, I was able to receive this output:
test {ham} ham test