Here's a quick dirty way that will work for simple samples and for valid html, and probably will cause problems with invalid html:
<?php
$html='Hi 3456; <a href="?id=4456">your code: 345</a> another 234';
$html = preg_replace('|(>[^<\d]*)(\d+)([^<\d]*</)|', '$1{NUM_WAS_HERE}$3', $html);//match between tags
$html = preg_replace('|^([^<\d]*)(\d+)([^<\d]*<)|', '$1{NUM_WAS_HERE}$3', $html);//beginning of the string
$html = preg_replace('|(>[^<\d]*)(\d+)([^<\d]*)$|', '$1{NUM_WAS_HERE}$3', $html);//end of the string
echo $html, "\n";//outputs: Hi {NUM_WAS_HERE}; <a href="?id=4456">your code: {NUM_WAS_HERE}</a> another {NUM_WAS_HERE}
As @Reinis recommended, using an html parser is the good secure way to achieve this.