protected static function doReplacement($matches)
{
// See how the regex above works out.
//print_r($matches);
// From count, we can tell whether we got a
// char, num, or bare ampersand.
$count = count($matches);
switch ($count) {
case 2:
// We have a character entity
return '&#' . self::replaceEntity($matches[1]) . ';';
case 3:
case 4:
// we have a numeric entity
return '&#' . $matches[$count - 1] . ';';
case 5:
// We have an unescaped ampersand.
return '&';
}
}