- preg_replace_callback: documentation ( source)
- sprintf: documentation ( source)
<?php
echo preg_replace_callback('/\d+/', function($match){
$match[0] = intval($match[0]);
if ($match[0]<100) {
return sprintf("%'.03d", $match[0]);
} else {
return $match[1];
}
}, 'H_000100');