PHP How to encode text into a numeric object?

I have xml like this:

<formula type="inline">
    <default:math xmlns="http://www.w3.org/1998/Math/MathML">
        <default:mi>
            &Zopf;
        </default:mi>
    </default:math>
</formula>

My goal is to get rid of all special objects, such as &Zopf;, replacing them with their numerical representations of entities.

I tried:

$test    = <content of the xml>;
$convmap = array(0x80, 0xffff, 0, 0xffff);
$test    = mb_encode_numericentity($test, $convmap, 'UTF-8');

But this will not replace &Zopf;any idea?

My goal is to get:

&#8484; 

as shown here: http://www.fileformat.info/info/unicode/char/2124/index.htm

Thanks.

+4
source share
2 answers

Your converter converts your LaTeX to MathML, not HTML objects. You need something that is converted directly to HTML symbolic links, or MathML to HTML symbol link converter .

htmlentities:

htmlentities($symbolsToEncode, ENT_XML1, 'UTF-8');

http://pt1.php.net/htmlentities

ENT_XML1 ENT_SUBSTITUTE, Unicode .

strtr :

$chars = array(
    "\x8484" => "&#x8484;"
    ...
);

$convertedXML = strtr($xml, $chars);

http://php.net/strtr

- - GitHub.

+1

, :

function decodeNamedEntities($string) {
  static $entities = NULL;
  if (NULL === $entities) {
    $entities = array_flip(
      array_diff(
        get_html_translation_table(HTML_ENTITIES, ENT_COMPAT | ENT_HTML5, 'UTF-8'),
        get_html_translation_table(HTML_ENTITIES, ENT_COMPAT | ENT_XML1, 'UTF-8')
      )
    );
  }
  return str_replace(array_keys($entities), $entities, $string);
}

htmlentities , .

0

All Articles