<?php

    function html_character_reference_decode($string, $encoding='UTF-8', $fixMappingBug=true) {
        $deref = create_function('$match', '
            if (strtolower($match[1][0]) === "x") {
                $codepoint = intval(substr($match[1], 1), 16);
            } else {
                $codepoint = intval($match[1], 10);
            }
            // @see http://w...content-available-to-author-only...t.fi/~jkorpela/www/windows-chars.html
            if ($fixMappingBug && $codepoint >= 130 && $codepoint <= 159) {
                $mapping = array(
                    8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249,
                    338, 141, 142, 143, 144, 8216, 8217, 8220, 8221, 8226,
                    8211, 8212, 732, 8482, 353, 8250, 339, 157, 158, 376);
                $codepoint = $mapping[$codepoint-130];
            }
var_dump($codepoint);
            return mb_convert_encoding(pack("N", $codepoint), $encoding, "UTF-32BE");
        ');
        return preg_replace_callback('/&#(x[0-9a-f]+|[0-9]+);/i', $deref, $string);
    }

var_dump(html_character_reference_decode('&#151;'));