<?php // -*- coding: utf-8 -*-

/** \file alphanormalize-test.php
 * (June 17, 2020)
 *
 * \brief PHP/HTML page to test alphanormalize_php.
 */

ini_set('display_errors''stdout');
ini_set('display_startup_errors'1);
ini_set('html_errors'1);

error_reporting(-1);

assert_options(ASSERT_ACTIVEtrue);
assert_options(ASSERT_WARNINGtrue);
assert_options(ASSERT_BAILtrue);

mb_internal_encoding('UTF-8');

require_once 
'alphanormalize.inc';

require_once 
'html_entities_entitydefs.inc';
require_once 
'html_entities_name2codepoint.inc';
require_once 
'html_entities_codepoint2name.inc';

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Reply-To" content="olivier.pirson.opi@gmail.com" />

    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>alphanormalize_php &ndash; tests</title>

    <meta name="copyright" content="&copy; Olivier Pirson" />
    <meta name="author" content="Olivier Pirson" />
    <meta name="date-creation-yyyymmdd" content="20101005" />
    <meta name="date-revision-yyyymmdd" content="20200617" />
    <meta name="description" content="Simple functions to remove accents and  replace non-alphanumeric characters." />
    <meta name="keywords" content="PHP, character, accents, Greek" />

    <style type="text/css">
h1 {
    margin: 1ex 0 0;
    text-align:center;
}

table { border-collapse: collapse; }

tr { vertical-align: top; }

tr.sep { border-top:solid 3px silver; }

th {
    font-family: Dina, monospace;
    font-weight: normal;
    text-align: left;
}

th,
td {
    border: solid 1px silver;
    white-space: nowrap;
}
td.sep { background-color: silver; }

hr {
    border-style: none;
    border-top: dotted 1px silver;
}

a.mail:link {
    background-color: inherit;
    color: green;
}
a.mail:visited {
    background-color: inherit;
    color: olive;
}

div { margin-top: 3ex; }

pre { margin: 0; }

.center { text-align: center; }

.smallskip { margin-top: 1ex; }
.bigskip    { margin-top: 3ex; }
.bigbigskip { margin-top: 6ex; }
.bigbigbigskip { margin-top: 9ex; }

.green { color: green; }
.red { color: red; }

.surname { font-variant: small-caps; }
    </style>
  </head>
  <body>
    <h1><a rel="nofollow" href="https://bitbucket.org/OPiMedia/alphanormalize_php" style="text-decoration:none"><img src="https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2020/Jun/12/1411058763-4-alphanormalize_php-logo_avatar.png" width="48" height="48" alt="" style="border:none; vertical-align:top" />&nbsp;</a><a href="https://bitbucket.org/OPiMedia/alphanormalize_php"><tt>alphanormalize_php</tt></a> &ndash; tests</h1>
    <div class="smallskip center">
      <a rel="nofollow" lang="fr" href="http://www.opimedia.be/" style="text-decoration:none"><img src="http://www.opimedia.be/_png/OPi.png" width="41" height="34" alt="" style="border:none; vertical-align:middle" />&nbsp;</a><a lang="fr" href="http://www.opimedia.be/">Olivier <span class="surname">Pirson</span></a>
      &ndash;
      <a class="mail" href="mailto:olivier.pirson.opi@gmail.com?subject=[alphanormalize_php]"><tt>olivier.pirson.opi@gmail.com</tt></a>
      &ndash;
      v.<?php echo preg_replace('/---/''&ndash;', \Alphanormalize\version()); ?>
    </div>
    <div class="smallskip center">
      <?php echo 'PHP version 'PHP_VERSION?>
    </div>
    <ul>
      <li>Sources on Bitbucket: <a href="https://bitbucket.org/OPiMedia/alphanormalize_php"><tt>https://bitbucket.org/OPiMedia/alphanormalize_php</tt></a></li>
      <li><a href="http://www.opimedia.be/DS/webdev/PHP/alphanormalize-php/docs/">Online HTML documentation</a></li>
      <li><a href="http://www.opimedia.be/DS/webdev/PHP/alphanormalize-php/alphanormalize-test.php">Online simple test page</a></li>
    </ul>

    <div class="bigskip">
<?php

$s 
'<pre>Il était une fois&hellip; des <em>caractères</em> "bizarroïdes" (avec accent, cédille et compagnie, ou α, β, etc.)
accompagnés ou pas de formatage <em>(X)HTML</em>.
Je cherchais à m&rsquo;en débarrasser&nbsp;!
Ceci est ma solution.</pre>'
;

?>
      <table>
        <tr>
          <th>$s</th>
          <td class="sep"></td>
          <td><?php echo $s?></td>
        </tr>

        <tr class="sep">
          <th>mb_str_accentalpha_to_alpha($s)</th>
          <td class="sep"></td>
          <td><?php echo \Alphanormalize\mb_str_accentalpha_to_alpha($s); ?></td>
        </tr>
        <tr>
          <th>mb_str_greek_to_alpha($s)</th>
          <td class="sep"></td>
          <td><?php echo \Alphanormalize\mb_str_greek_to_alpha($s); ?></td>
        </tr>

        <tr class="sep">
          <th>htmlspecialchars($s)</th>
          <td class="sep"></td>
          <td><?php echo htmlspecialchars($s); ?></td>
        </tr>
        <tr>
          <th><strong>mb_str_alphanormalize($s)</strong></th>
          <td class="sep"></td>
          <td><?php echo \Alphanormalize\mb_str_alphanormalize($s); ?></td>
        </tr>
        <tr>
          <th><strong>mb_str_alphanormalize($s, true)</strong></th>
          <td class="sep"></td>
          <td><?php echo \Alphanormalize\mb_str_alphanormalize($strue); ?></td>
        </tr>
      </table>
    </div>

    <div>
      <tt>$ACCENTALPHA_TO_ALPHA[]</tt>:
      <table>
<?php

require 'accentalpha_to_alpha.inc';

echo 
'        <tr>
        <th>$c</th>
'
;

foreach (
$ACCENTALPHA_TO_ALPHA as $c=>$v) {
  if (
in_array($c, array('À''ß''à''Œ'), true)) {
    echo 
'<td class="sep"></td>
'
;
  }

  echo 
'<td>'$c'</td>
'
;
}

echo 
'        </tr>
        <tr class="sep">
        <th>$ACCENTALPHA_TO_ALPHA[$c]</th>
'
;

foreach (
$ACCENTALPHA_TO_ALPHA as $c=>$v) {
  if (
in_array($c, array('À''ß''à''Œ'), true)) {
    echo 
'<td class="sep"></td>
'
;
  }

  echo 
'<td>'$v'</td>
'
;
}

echo 
'        </tr>
'
;

?>
      </table>
    </div>

    <div>
      <tt>$GREEK_TO_ALPHA[]</tt>
      (Adopts the standard <acronym>ONU</acronym>/<acronym>ELOT</acronym>:
       see. <i>Memento <a href="http://www.opimedia.be/DS/mementos/grecs.htm">grecs</a></i>):
      <table>
<?php

require 'greek_to_alpha.inc';

echo 
'        <tr>
        <th>$c</th>
'
;

foreach (
$GREEK_TO_ALPHA as $c=>$v) {
  if (
in_array($c, array('Α''α''ς''σ''ϑ'), true)) {
    echo 
'<td class="sep"></td>
'
;
  }

  echo 
'<td>'$c'</td>
'
;
}

echo 
'        </tr>
        <tr class="sep">
        <th>$GREEK_TO_ALPHA[$c]</th>
'
;

foreach (
$GREEK_TO_ALPHA as $c=>$v) {
  if (
in_array($c, array('Α''α''ς''σ''ϑ'), true)) {
    echo 
'<td class="sep"></td>
'
;
  }

  echo 
'<td>'$v'</td>
'
;
}

echo 
'        </tr>
'
;

?>
      </table>
    </div>

    <div class="bigbigbigskip">
      Associative table returned by the PHP function
      <tt>get_html_translation_table(HTML_SPECIALCHARS)</tt>:
      <table>
<?php

echo '        <tr>
        <th>htmlspecialchars($c)</th>
        <td class="sep"></td>
'
;

foreach (
get_html_translation_table(HTML_SPECIALCHARS) as $c=>$v) {
  echo 
'<td>'htmlspecialchars($c), '</td>
'
;
}

echo 
'        </tr>
        <tr class="sep">
        <th>htmlspecialchars(get_html_translation_table(HTML_SPECIALCHARS)[$c])</th>
        <td class="sep"></td>
'
;

foreach (
get_html_translation_table(HTML_SPECIALCHARS) as $c=>$v) {
  echo 
'<td>'htmlspecialchars($v), '</td>
'
;
}

echo 
'        </tr>
        <tr>
        <th>mb_str_alphanormalize($c)</th>
        <td class="sep"></td>
'
;

foreach (
get_html_translation_table(HTML_SPECIALCHARS) as $c=>$v) {
  echo 
'<td>', \Alphanormalize\mb_str_alphanormalize($c), '</td>
'
;
}

echo 
'        </tr>
'
;

?>
      </table>
    </div>

    <div>
      Associative table returned by the PHP function
      <tt>get_html_translation_table(HTML_ENTITIES)</tt>:
      <table>
<?php

echo '        <tr>
        <th>htmlspecialchars(utf8_encode($c))</th>
        <td class="sep"></td>
'
;

foreach (
get_html_translation_table(HTML_ENTITIES) as $c=>$v) {
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$c utf8_encode($c);
  }
  echo 
'<td', (in_array($c$HTML_ENTITIES_ENTITYDEFStrue)
               ? 
'>'
               
' class="red">'), htmlspecialchars($c), '</td>
'
;
}

echo 
'        </tr>
        <tr class="sep">
        <th>htmlspecialchars(get_html_translation_table(HTML_ENTITIES)[$c])</th>
        <td class="sep"></td>
'
;

foreach (
get_html_translation_table(HTML_ENTITIES) as $c=>$v) {
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$c utf8_encode($c);
  }
  echo 
'<td', (in_array($c$HTML_ENTITIES_ENTITYDEFStrue)
               ? 
'>'
               
' class="red">'), htmlspecialchars($v), '</td>
'
;
}

echo 
'        </tr>
        <tr>
        <th>mb_str_alphanormalize(utf8_encode($c))</th>
        <td class="sep"></td>
'
;

foreach (
get_html_translation_table(HTML_ENTITIES) as $c=>$v) {
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$c utf8_encode($c);
  }
  echo 
'<td', (in_array($c$HTML_ENTITIES_ENTITYDEFStrue)
               ? 
'>'
               
' class="red">'), \Alphanormalize\mb_str_alphanormalize($c), '</td>
'
;
}

echo 
'        </tr>
'
;

?>
      </table>
      (<?php echo count(get_html_translation_table(HTML_ENTITIES)); ?> éléments)
    </div>

    <div class="bigbigbigskip">
      Three associative tables (copied from Python dictionary of module
      <a href="http://docs.python.org/py3k/library/html.entities.html#module-html.entities"><tt>html.entities</tt></a>):<br />
      <tt>$HTML_ENTITIES_ENTITYDEFS[]</tt>:
      <table>
<?php

$array_get_html_translation_table 
get_html_translation_table(HTML_ENTITIES);

echo 
'        <tr>
        <th>$k</th>
        <td class="sep"></td>
'
;

foreach (
$HTML_ENTITIES_ENTITYDEFS as $k=>$v) {
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$v utf8_decode($v);
  }

  echo 
'<td', (array_key_exists($v$array_get_html_translation_table)
               ? 
'>'
               
' class="green">'), $k'</td>
'
;
}

echo 
'        </tr>
        <tr class="sep">
        <th>htmlspecialchars($HTML_ENTITIES_ENTITYDEFS[$k])</th>
        <td class="sep"></td>
'
;
$nb_diff 0;

foreach (
$HTML_ENTITIES_ENTITYDEFS as $k=>$v) {
  
$dv = (version_compare(PHP_VERSION'5.4.0') < 0
         
utf8_decode($v)
         : 
$v);

  if (!
array_key_exists($dv$array_get_html_translation_table)) {
    
$nb_diff++;
  }
  echo 
'<td', (array_key_exists($dv$array_get_html_translation_table)
               ? 
'>'
               
' class="green">'), htmlspecialchars($v), '</td>
'
;
}

echo 
'        </tr>
'
;

?>
      </table>
      (In <span class="green">green</span> the <?php echo $nb_diff?> items over <?php echo count($HTML_ENTITIES_ENTITYDEFS); ?>
       which are not in <tt>get_html_translation_table(HTML_ENTITIES)</tt>.
       Previous PHP 5.4, all HTML entities are not supported!)
    </div>

    <div>
      <tt>$HTML_ENTITIES_NAME2CODEPOINT[]</tt>:
      <table>
<?php

echo '        <tr>
        <th>$k</th>
        <td class="sep"></td>
'
;

foreach (
$HTML_ENTITIES_NAME2CODEPOINT as $k=>$v) {
  
$c $HTML_ENTITIES_ENTITYDEFS[$k];
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$c utf8_decode($c);
  }

  echo 
'<td', (array_key_exists($c$array_get_html_translation_table)
               ? 
'>'
               
' class="green">'), $k'</td>
'
;
}

echo 
'        </tr>
        <tr class="sep">
        <th>$HTML_ENTITIES_NAME2CODEPOINT[$k]</th>
        <td class="sep"></td>
'
;

foreach (
$HTML_ENTITIES_NAME2CODEPOINT as $k=>$v) {
  
$c $HTML_ENTITIES_ENTITYDEFS[$k];
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$c utf8_decode($c);
  }

  echo 
'<td', (array_key_exists($c$array_get_html_translation_table)
               ? 
'>'
               
' class="green">'), $v'</td>
'
;
}

echo 
'        </tr>
'
;

?>
      </table>
    </div>

    <div>
      <tt>$HTML_ENTITIES_CODEPOINT2NAME[]</tt>:
      <table>
<?php

echo '        <tr>
        <th>$k</th>
        <td class="sep"></td>
'
;

foreach (
$HTML_ENTITIES_CODEPOINT2NAME as $k=>$v) {
  if (
$k === 338) {
    echo 
'<td class="sep"></td>
'
;
  }

  
$c $HTML_ENTITIES_ENTITYDEFS[$v];
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$c utf8_decode($c);
  }

  echo 
'<td', (array_key_exists($c$array_get_html_translation_table)
               ? 
'>'
               
' class="green">'), $k'</td>
'
;
}

echo 
'        </tr>
        <tr class="sep">
        <th>$HTML_ENTITIES_CODEPOINT2NAME[$k]</th>
        <td class="sep"></td>
'
;

foreach (
$HTML_ENTITIES_CODEPOINT2NAME as $k=>$v) {
  if (
$k === 338) {
    echo 
'<td class="sep"></td>
'
;
  }

  
$c $HTML_ENTITIES_ENTITYDEFS[$v];
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$c utf8_decode($c);
  }

  echo 
'<td', (array_key_exists($c$array_get_html_translation_table)
               ? 
'>'
               
' class="green">'), $v'</td>
'
;
}

echo 
'        </tr>
'
;

?>
      </table>
    </div>

<?php

/* Tests */
foreach (get_html_translation_table(HTML_ENTITIES) as $c=>$v) {
  if (
version_compare(PHP_VERSION'5.4.0') < 0) {
    
$c utf8_encode($c);
  }
  
$v mb_substr($v1mb_strlen($v) - 2);
  
assert($HTML_ENTITIES_ENTITYDEFS[$v] === $c);
}

foreach (
$HTML_ENTITIES_NAME2CODEPOINT as $k=>$v) {
  
assert($HTML_ENTITIES_CODEPOINT2NAME[$HTML_ENTITIES_NAME2CODEPOINT[$k]] === $k);
}

foreach (
$HTML_ENTITIES_CODEPOINT2NAME as $k=>$v) {
  
assert($HTML_ENTITIES_NAME2CODEPOINT[$HTML_ENTITIES_CODEPOINT2NAME[$k]] === $k);
}

?>
  </body>
</html>

<?php // -*- coding: utf-8 -*-

/** \file alphanormalize-test.php
 * (June 17, 2020)
 *
 * \brief PHP/HTML page to test alphanormalize_php.
 */

ini_set('display_errors', 'stdout');
ini_set('display_startup_errors', 1);
ini_set('html_errors', 1);

error_reporting(-1);

assert_options(ASSERT_ACTIVE, true);
assert_options(ASSERT_WARNING, true);
assert_options(ASSERT_BAIL, true);

mb_internal_encoding('UTF-8');

require_once 'alphanormalize.inc';

require_once 'html_entities_entitydefs.inc';
require_once 'html_entities_name2codepoint.inc';
require_once 'html_entities_codepoint2name.inc';

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Reply-To" content="olivier.pirson.opi@gmail.com" />

    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>alphanormalize_php &ndash; tests</title>

    <meta name="copyright" content="&copy; Olivier Pirson" />
    <meta name="author" content="Olivier Pirson" />
    <meta name="date-creation-yyyymmdd" content="20101005" />
    <meta name="date-revision-yyyymmdd" content="20200617" />
    <meta name="description" content="Simple functions to remove accents and  replace non-alphanumeric characters." />
    <meta name="keywords" content="PHP, character, accents, Greek" />

    <style type="text/css">
h1 {
    margin: 1ex 0 0;
    text-align:center;
}

table { border-collapse: collapse; }

tr { vertical-align: top; }

tr.sep { border-top:solid 3px silver; }

th {
    font-family: Dina, monospace;
    font-weight: normal;
    text-align: left;
}

th,
td {
    border: solid 1px silver;
    white-space: nowrap;
}
td.sep { background-color: silver; }

hr {
    border-style: none;
    border-top: dotted 1px silver;
}

a.mail:link {
    background-color: inherit;
    color: green;
}
a.mail:visited {
    background-color: inherit;
    color: olive;
}

div { margin-top: 3ex; }

pre { margin: 0; }

.center { text-align: center; }

.smallskip { margin-top: 1ex; }
.bigskip    { margin-top: 3ex; }
.bigbigskip { margin-top: 6ex; }
.bigbigbigskip { margin-top: 9ex; }

.green { color: green; }
.red { color: red; }

.surname { font-variant: small-caps; }
    </style>
  </head>
  <body>
    <h1><a rel="nofollow" href="https://bitbucket.org/OPiMedia/alphanormalize_php" style="text-decoration:none"><img src="https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2020/Jun/12/1411058763-4-alphanormalize_php-logo_avatar.png" width="48" height="48" alt="" style="border:none; vertical-align:top" />&nbsp;</a><a href="https://bitbucket.org/OPiMedia/alphanormalize_php"><tt>alphanormalize_php</tt></a> &ndash; tests</h1>
    <div class="smallskip center">
      <a rel="nofollow" lang="fr" href="http://www.opimedia.be/" style="text-decoration:none"><img src="http://www.opimedia.be/_png/OPi.png" width="41" height="34" alt="" style="border:none; vertical-align:middle" />&nbsp;</a><a lang="fr" href="http://www.opimedia.be/">Olivier <span class="surname">Pirson</span></a>
      &ndash;
      <a class="mail" href="mailto:olivier.pirson.opi@gmail.com?subject=[alphanormalize_php]"><tt>olivier.pirson.opi@gmail.com</tt></a>
      &ndash;
      v.<?php echo preg_replace('/---/', '&ndash;', \Alphanormalize\version()); ?>
    </div>
    <div class="smallskip center">
      <?php echo 'PHP version ', PHP_VERSION; ?>
    </div>
    <ul>
      <li>Sources on Bitbucket: <a href="https://bitbucket.org/OPiMedia/alphanormalize_php"><tt>https://bitbucket.org/OPiMedia/alphanormalize_php</tt></a></li>
      <li><a href="http://www.opimedia.be/DS/webdev/PHP/alphanormalize-php/docs/">Online HTML documentation</a></li>
      <li><a href="http://www.opimedia.be/DS/webdev/PHP/alphanormalize-php/alphanormalize-test.php">Online simple test page</a></li>
    </ul>

    <div class="bigskip">
<?php

$s = '<pre>Il était une fois&hellip; des <em>caractères</em> "bizarroïdes" (avec accent, cédille et compagnie, ou α, β, etc.)
accompagnés ou pas de formatage <em>(X)HTML</em>.
Je cherchais à m&rsquo;en débarrasser&nbsp;!
Ceci est ma solution.</pre>';

?>
      <table>
        <tr>
          <th>$s</th>
          <td class="sep"></td>
          <td><?php echo $s; ?></td>
        </tr>

        <tr class="sep">
          <th>mb_str_accentalpha_to_alpha($s)</th>
          <td class="sep"></td>
          <td><?php echo \Alphanormalize\mb_str_accentalpha_to_alpha($s); ?></td>
        </tr>
        <tr>
          <th>mb_str_greek_to_alpha($s)</th>
          <td class="sep"></td>
          <td><?php echo \Alphanormalize\mb_str_greek_to_alpha($s); ?></td>
        </tr>

        <tr class="sep">
          <th>htmlspecialchars($s)</th>
          <td class="sep"></td>
          <td><?php echo htmlspecialchars($s); ?></td>
        </tr>
        <tr>
          <th><strong>mb_str_alphanormalize($s)</strong></th>
          <td class="sep"></td>
          <td><?php echo \Alphanormalize\mb_str_alphanormalize($s); ?></td>
        </tr>
        <tr>
          <th><strong>mb_str_alphanormalize($s, true)</strong></th>
          <td class="sep"></td>
          <td><?php echo \Alphanormalize\mb_str_alphanormalize($s, true); ?></td>
        </tr>
      </table>
    </div>

    <div>
      <tt>$ACCENTALPHA_TO_ALPHA[]</tt>:
      <table>
<?php

require 'accentalpha_to_alpha.inc';

echo '        <tr>
        <th>$c</th>
';

foreach ($ACCENTALPHA_TO_ALPHA as $c=>$v) {
  if (in_array($c, array('À', 'ß', 'à', 'Œ'), true)) {
    echo '<td class="sep"></td>
';
  }

  echo '<td>', $c, '</td>
';
}

echo '        </tr>
        <tr class="sep">
        <th>$ACCENTALPHA_TO_ALPHA[$c]</th>
';

foreach ($ACCENTALPHA_TO_ALPHA as $c=>$v) {
  if (in_array($c, array('À', 'ß', 'à', 'Œ'), true)) {
    echo '<td class="sep"></td>
';
  }

  echo '<td>', $v, '</td>
';
}

echo '        </tr>
';

?>
      </table>
    </div>

    <div>
      <tt>$GREEK_TO_ALPHA[]</tt>
      (Adopts the standard <acronym>ONU</acronym>/<acronym>ELOT</acronym>:
       see. <i>Memento <a href="http://www.opimedia.be/DS/mementos/grecs.htm">grecs</a></i>):
      <table>
<?php

require 'greek_to_alpha.inc';

echo '        <tr>
        <th>$c</th>
';

foreach ($GREEK_TO_ALPHA as $c=>$v) {
  if (in_array($c, array('Α', 'α', 'ς', 'σ', 'ϑ'), true)) {
    echo '<td class="sep"></td>
';
  }

  echo '<td>', $c, '</td>
';
}

echo '        </tr>
        <tr class="sep">
        <th>$GREEK_TO_ALPHA[$c]</th>
';

foreach ($GREEK_TO_ALPHA as $c=>$v) {
  if (in_array($c, array('Α', 'α', 'ς', 'σ', 'ϑ'), true)) {
    echo '<td class="sep"></td>
';
  }

  echo '<td>', $v, '</td>
';
}

echo '        </tr>
';

?>
      </table>
    </div>

    <div class="bigbigbigskip">
      Associative table returned by the PHP function
      <tt>get_html_translation_table(HTML_SPECIALCHARS)</tt>:
      <table>
<?php

echo '        <tr>
        <th>htmlspecialchars($c)</th>
        <td class="sep"></td>
';

foreach (get_html_translation_table(HTML_SPECIALCHARS) as $c=>$v) {
  echo '<td>', htmlspecialchars($c), '</td>
';
}

echo '        </tr>
        <tr class="sep">
        <th>htmlspecialchars(get_html_translation_table(HTML_SPECIALCHARS)[$c])</th>
        <td class="sep"></td>
';

foreach (get_html_translation_table(HTML_SPECIALCHARS) as $c=>$v) {
  echo '<td>', htmlspecialchars($v), '</td>
';
}

echo '        </tr>
        <tr>
        <th>mb_str_alphanormalize($c)</th>
        <td class="sep"></td>
';

foreach (get_html_translation_table(HTML_SPECIALCHARS) as $c=>$v) {
  echo '<td>', \Alphanormalize\mb_str_alphanormalize($c), '</td>
';
}

echo '        </tr>
';

?>
      </table>
    </div>

    <div>
      Associative table returned by the PHP function
      <tt>get_html_translation_table(HTML_ENTITIES)</tt>:
      <table>
<?php

echo '        <tr>
        <th>htmlspecialchars(utf8_encode($c))</th>
        <td class="sep"></td>
';

foreach (get_html_translation_table(HTML_ENTITIES) as $c=>$v) {
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $c = utf8_encode($c);
  }
  echo '<td', (in_array($c, $HTML_ENTITIES_ENTITYDEFS, true)
               ? '>'
               : ' class="red">'), htmlspecialchars($c), '</td>
';
}

echo '        </tr>
        <tr class="sep">
        <th>htmlspecialchars(get_html_translation_table(HTML_ENTITIES)[$c])</th>
        <td class="sep"></td>
';

foreach (get_html_translation_table(HTML_ENTITIES) as $c=>$v) {
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $c = utf8_encode($c);
  }
  echo '<td', (in_array($c, $HTML_ENTITIES_ENTITYDEFS, true)
               ? '>'
               : ' class="red">'), htmlspecialchars($v), '</td>
';
}

echo '        </tr>
        <tr>
        <th>mb_str_alphanormalize(utf8_encode($c))</th>
        <td class="sep"></td>
';

foreach (get_html_translation_table(HTML_ENTITIES) as $c=>$v) {
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $c = utf8_encode($c);
  }
  echo '<td', (in_array($c, $HTML_ENTITIES_ENTITYDEFS, true)
               ? '>'
               : ' class="red">'), \Alphanormalize\mb_str_alphanormalize($c), '</td>
';
}

echo '        </tr>
';

?>
      </table>
      (<?php echo count(get_html_translation_table(HTML_ENTITIES)); ?> éléments)
    </div>

    <div class="bigbigbigskip">
      Three associative tables (copied from Python dictionary of module
      <a href="http://docs.python.org/py3k/library/html.entities.html#module-html.entities"><tt>html.entities</tt></a>):<br />
      <tt>$HTML_ENTITIES_ENTITYDEFS[]</tt>:
      <table>
<?php

$array_get_html_translation_table = get_html_translation_table(HTML_ENTITIES);

echo '        <tr>
        <th>$k</th>
        <td class="sep"></td>
';

foreach ($HTML_ENTITIES_ENTITYDEFS as $k=>$v) {
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $v = utf8_decode($v);
  }

  echo '<td', (array_key_exists($v, $array_get_html_translation_table)
               ? '>'
               : ' class="green">'), $k, '</td>
';
}

echo '        </tr>
        <tr class="sep">
        <th>htmlspecialchars($HTML_ENTITIES_ENTITYDEFS[$k])</th>
        <td class="sep"></td>
';
$nb_diff = 0;

foreach ($HTML_ENTITIES_ENTITYDEFS as $k=>$v) {
  $dv = (version_compare(PHP_VERSION, '5.4.0') < 0
         ? utf8_decode($v)
         : $v);

  if (!array_key_exists($dv, $array_get_html_translation_table)) {
    $nb_diff++;
  }
  echo '<td', (array_key_exists($dv, $array_get_html_translation_table)
               ? '>'
               : ' class="green">'), htmlspecialchars($v), '</td>
';
}

echo '        </tr>
';

?>
      </table>
      (In <span class="green">green</span> the <?php echo $nb_diff; ?> items over <?php echo count($HTML_ENTITIES_ENTITYDEFS); ?>
       which are not in <tt>get_html_translation_table(HTML_ENTITIES)</tt>.
       Previous PHP 5.4, all HTML entities are not supported!)
    </div>

    <div>
      <tt>$HTML_ENTITIES_NAME2CODEPOINT[]</tt>:
      <table>
<?php

echo '        <tr>
        <th>$k</th>
        <td class="sep"></td>
';

foreach ($HTML_ENTITIES_NAME2CODEPOINT as $k=>$v) {
  $c = $HTML_ENTITIES_ENTITYDEFS[$k];
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $c = utf8_decode($c);
  }

  echo '<td', (array_key_exists($c, $array_get_html_translation_table)
               ? '>'
               : ' class="green">'), $k, '</td>
';
}

echo '        </tr>
        <tr class="sep">
        <th>$HTML_ENTITIES_NAME2CODEPOINT[$k]</th>
        <td class="sep"></td>
';

foreach ($HTML_ENTITIES_NAME2CODEPOINT as $k=>$v) {
  $c = $HTML_ENTITIES_ENTITYDEFS[$k];
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $c = utf8_decode($c);
  }

  echo '<td', (array_key_exists($c, $array_get_html_translation_table)
               ? '>'
               : ' class="green">'), $v, '</td>
';
}

echo '        </tr>
';

?>
      </table>
    </div>

    <div>
      <tt>$HTML_ENTITIES_CODEPOINT2NAME[]</tt>:
      <table>
<?php

echo '        <tr>
        <th>$k</th>
        <td class="sep"></td>
';

foreach ($HTML_ENTITIES_CODEPOINT2NAME as $k=>$v) {
  if ($k === 338) {
    echo '<td class="sep"></td>
';
  }

  $c = $HTML_ENTITIES_ENTITYDEFS[$v];
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $c = utf8_decode($c);
  }

  echo '<td', (array_key_exists($c, $array_get_html_translation_table)
               ? '>'
               : ' class="green">'), $k, '</td>
';
}

echo '        </tr>
        <tr class="sep">
        <th>$HTML_ENTITIES_CODEPOINT2NAME[$k]</th>
        <td class="sep"></td>
';

foreach ($HTML_ENTITIES_CODEPOINT2NAME as $k=>$v) {
  if ($k === 338) {
    echo '<td class="sep"></td>
';
  }

  $c = $HTML_ENTITIES_ENTITYDEFS[$v];
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $c = utf8_decode($c);
  }

  echo '<td', (array_key_exists($c, $array_get_html_translation_table)
               ? '>'
               : ' class="green">'), $v, '</td>
';
}

echo '        </tr>
';

?>
      </table>
    </div>

<?php

/* Tests */
foreach (get_html_translation_table(HTML_ENTITIES) as $c=>$v) {
  if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    $c = utf8_encode($c);
  }
  $v = mb_substr($v, 1, mb_strlen($v) - 2);
  assert($HTML_ENTITIES_ENTITYDEFS[$v] === $c);
}

foreach ($HTML_ENTITIES_NAME2CODEPOINT as $k=>$v) {
  assert($HTML_ENTITIES_CODEPOINT2NAME[$HTML_ENTITIES_NAME2CODEPOINT[$k]] === $k);
}

foreach ($HTML_ENTITIES_CODEPOINT2NAME as $k=>$v) {
  assert($HTML_ENTITIES_NAME2CODEPOINT[$HTML_ENTITIES_CODEPOINT2NAME[$k]] === $k);
}

?>
  </body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539

PHPstripDEBUG

« < > »

13565 b

Warnings:
525 529 533
'<?php':
1 107 110 119 131 137 142 148 153 158 166 211 255 300 354 362 408 416 463 517
stripped/alphanormalize_php/alphanormalize-test.php 12885 b (≅95%)
source: utf_8   destination: utf_8   XHTML: utf_8
JavaScript is disabled!
© Olivier Pirson — DragonSoft DS — v.01.01.04 — June 19, 2020
This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; see the source for copying conditions.