lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all. Somedays algo, someone sen a mail to the list asking for a htmlentities function.

Well, I think about how can I get a more complete list of htmlentities to use as the table to the translation..

As i'm a PHP programmer, I find in PHP a function called get_html_translation_table.

With it, I get to this Lua table:

entities = {
[' '] = ' ' ,
['¡'] = '¡' ,
['¢'] = '¢' ,
['£'] = '£' ,
['¤'] = '¤' ,
['¥'] = '¥' ,
['¦'] = '¦' ,
['§'] = '§' ,
['¨'] = '¨' ,
['©'] = '©' ,
['ª'] = 'ª' ,
['«'] = '«' ,
['¬'] = '¬' ,
['­'] = '­' ,
['®'] = '®' ,
['¯'] = '¯' ,
['°'] = '°' ,
['±'] = '±' ,
['²'] = '²' ,
['³'] = '³' ,
['´'] = '´' ,
['µ'] = 'µ' ,
['¶'] = '¶' ,
['·'] = '·' ,
['¸'] = '¸' ,
['¹'] = '¹' ,
['º'] = 'º' ,
['»'] = '»' ,
['¼'] = '¼' ,
['½'] = '½' ,
['¾'] = '¾' ,
['¿'] = '¿' ,
['À'] = 'À' ,
['Á'] = 'Á' ,
['Â'] = 'Â' ,
['Ã'] = 'Ã' ,
['Ä'] = 'Ä' ,
['Å'] = 'Å' ,
['Æ'] = 'Æ' ,
['Ç'] = 'Ç' ,
['È'] = 'È' ,
['É'] = 'É' ,
['Ê'] = 'Ê' ,
['Ë'] = 'Ë' ,
['Ì'] = 'Ì' ,
['Í'] = 'Í' ,
['Î'] = 'Î' ,
['Ï'] = 'Ï' ,
['Ð'] = 'Ð' ,
['Ñ'] = 'Ñ' ,
['Ò'] = 'Ò' ,
['Ó'] = 'Ó' ,
['Ô'] = 'Ô' ,
['Õ'] = 'Õ' ,
['Ö'] = 'Ö' ,
['×'] = '×' ,
['Ø'] = 'Ø' ,
['Ù'] = 'Ù' ,
['Ú'] = 'Ú' ,
['Û'] = 'Û' ,
['Ü'] = 'Ü' ,
['Ý'] = 'Ý' ,
['Þ'] = 'Þ' ,
['ß'] = 'ß' ,
['à'] = 'à' ,
['á'] = 'á' ,
['â'] = 'â' ,
['ã'] = 'ã' ,
['ä'] = 'ä' ,
['å'] = 'å' ,
['æ'] = 'æ' ,
['ç'] = 'ç' ,
['è'] = 'è' ,
['é'] = 'é' ,
['ê'] = 'ê' ,
['ë'] = 'ë' ,
['ì'] = 'ì' ,
['í'] = 'í' ,
['î'] = 'î' ,
['ï'] = 'ï' ,
['ð'] = 'ð' ,
['ñ'] = 'ñ' ,
['ò'] = 'ò' ,
['ó'] = 'ó' ,
['ô'] = 'ô' ,
['õ'] = 'õ' ,
['ö'] = 'ö' ,
['÷'] = '÷' ,
['ø'] = 'ø' ,
['ù'] = 'ù' ,
['ú'] = 'ú' ,
['û'] = 'û' ,
['ü'] = 'ü' ,
['ý'] = 'ý' ,
['þ'] = 'þ' ,
['ÿ'] = 'ÿ' ,
['"'] = '"' ,
["'"] = ''' ,
['<'] = '&lt;' ,
['>'] = '&gt;' ,
['&'] = '&amp;'
}

I hope that this will be useful to someone.

And, of course, Lua has a clearer and brilliant syntax than PHP, but, here's the PHP code that generated that list. :)


-------begin cut---------

<?php
$trans_table = get_html_translation_table(HTML_ENTITIES,ENT_QUOTES);
echo "entities = {\n";
$output ="";

    foreach($trans_table as $key=>$value) {
            $output .=  "['" . $key."'] = '". $value."' ,";                                         
  }

//echo($output);
$output = preg_replace("/,$/","",$output); // strips the last comma
$output = preg_replace("/'''/","\"'\"",$output); // transform ''' in "'"
$output = preg_replace("/,/",",\n",$output); // break lines
echo($output);

echo "\n}\n";
?>

---- end cut -------

Enjoy :)

[]'s
- Walter