Advertisement
Guest User

http://blog.qyy.fr - G. Qyy

a guest
Nov 4th, 2010
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.59 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Converts all entities of the XHTML Transitional's DTD in Unicode.
  5.  * DTD Section:
  6.  * <code>
  7.  *   <!--================ Character mnemonic entities =========================-->
  8.  *
  9.  *   <!ENTITY % HTMLlat1 PUBLIC
  10.  *      "-//W3C//ENTITIES Latin 1 for XHTML//EN"
  11.  *      "xhtml-lat1.ent">
  12.  *   %HTMLlat1;
  13.  *
  14.  *   <!ENTITY % HTMLsymbol PUBLIC
  15.  *      "-//W3C//ENTITIES Symbols for XHTML//EN"
  16.  *      "xhtml-symbol.ent">
  17.  *   %HTMLsymbol;
  18.  *
  19.  *   <!ENTITY % HTMLspecial PUBLIC
  20.  *      "-//W3C//ENTITIES Special for XHTML//EN"
  21.  *      "xhtml-special.ent">
  22.  *   %HTMLspecial;
  23.  * </code>
  24.  * @author G. Qyy
  25.  * @copyright Copyright (c) 2010 G. Qyy
  26.  * @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
  27.  * @link http://stackoverflow.com/q/4081090/492638
  28.  * @link http://blog.qyy.fr/2010/10/convertir-des-entites-xhtml-en-unicode.html
  29.  * @link http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
  30.  * @link http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
  31.  * @link http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent
  32.  * @link http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
  33.  * @param string $string <p>
  34.  * A string containing entities declared in the XHTML Transitional's DTD
  35.  * </p>
  36.  * @return string The provided string with all XHTML Transitional's
  37.  * entities converted to Unicode entities.
  38.  */
  39. function ConvertEntitiesToUnicode($string)
  40. {
  41.   $unicode = array(
  42.     '&#34;','&#38;','&#60;','&#62;','&#39;','&#338;','&#339;','&#352;',
  43.     '&#353;','&#376;','&#710;','&#732;','&#8194;','&#8195;','&#8201;',
  44.     '&#8204;','&#8205;','&#8206;','&#8207;','&#8211;','&#8212;','&#8216;',
  45.     '&#8217;','&#8218;','&#8220;','&#8221;','&#8222;','&#8224;','&#8225;',
  46.     '&#8240;','&#8249;','&#8250;','&#8364;','&#160;','&#161;','&#162;',
  47.     '&#163;','&#164;','&#165;','&#166;','&#167;','&#168;','&#169;','&#170;',
  48.     '&#171;','&#172;','&#173;','&#174;','&#175;','&#176;','&#177;','&#178;',
  49.     '&#179;','&#180;','&#181;','&#182;','&#183;','&#184;','&#185;','&#186;',
  50.     '&#187;','&#188;','&#189;','&#190;','&#191;','&#192;','&#193;','&#194;',
  51.     '&#195;','&#196;','&#197;','&#198;','&#199;','&#200;','&#201;','&#202;',
  52.     '&#203;','&#204;','&#205;','&#206;','&#207;','&#208;','&#209;','&#210;',
  53.     '&#211;','&#212;','&#213;','&#214;','&#215;','&#216;','&#217;','&#218;',
  54.     '&#219;','&#220;','&#221;','&#222;','&#223;','&#224;','&#225;','&#226;',
  55.     '&#227;','&#228;','&#229;','&#230;','&#231;','&#232;','&#233;','&#234;',
  56.     '&#235;','&#236;','&#237;','&#238;','&#239;','&#240;','&#241;','&#242;',
  57.     '&#243;','&#244;','&#245;','&#246;','&#247;','&#248;','&#249;','&#250;',
  58.     '&#251;','&#252;','&#253;','&#254;','&#255;','&#402;','&#913;','&#914;',
  59.     '&#915;','&#916;','&#917;','&#918;','&#919;','&#920;','&#921;','&#922;',
  60.     '&#923;','&#924;','&#925;','&#926;','&#927;','&#928;','&#929;','&#931;',
  61.     '&#932;','&#933;','&#934;','&#935;','&#936;','&#937;','&#945;','&#946;',
  62.     '&#947;','&#948;','&#949;','&#950;','&#951;','&#952;','&#953;','&#954;',
  63.     '&#955;','&#956;','&#957;','&#958;','&#959;','&#960;','&#961;','&#962;',
  64.     '&#963;','&#964;','&#965;','&#966;','&#967;','&#968;','&#969;','&#977;',
  65.     '&#978;','&#982;','&#8226;','&#8230;','&#8242;','&#8243;','&#8254;',
  66.     '&#8260;','&#8472;','&#8465;','&#8476;','&#8482;','&#8501;','&#8592;',
  67.     '&#8593;','&#8594;','&#8595;','&#8596;','&#8629;','&#8656;','&#8657;',
  68.     '&#8658;','&#8659;','&#8660;','&#8704;','&#8706;','&#8707;','&#8709;',
  69.     '&#8711;','&#8712;','&#8713;','&#8715;','&#8719;','&#8721;','&#8722;',
  70.     '&#8727;','&#8730;','&#8733;','&#8734;','&#8736;','&#8743;','&#8744;',
  71.     '&#8745;','&#8746;','&#8747;','&#8756;','&#8764;','&#8773;','&#8776;',
  72.     '&#8800;','&#8801;','&#8804;','&#8805;','&#8834;','&#8835;','&#8836;',
  73.     '&#8838;','&#8839;','&#8853;','&#8855;','&#8869;','&#8901;','&#8968;',
  74.     '&#8969;','&#8970;','&#8971;','&#9001;','&#9002;','&#9674;','&#9824;',
  75.     '&#9827;','&#9829;','&#9830;'
  76.   );
  77.  
  78.   $entities = array(
  79.     '&quot;','&amp;','&lt;','&gt;','&apos;','&OElig;','&oelig;','&Scaron;',
  80.     '&scaron;','&Yuml;','&circ;','&tilde;','&ensp;','&emsp;','&thinsp;',
  81.     '&zwnj;','&zwj;','&lrm;','&rlm;','&ndash;','&mdash;','&lsquo;','&rsquo;',
  82.     '&sbquo;','&ldquo;','&rdquo;','&bdquo;','&dagger;','&Dagger;','&permil;',
  83.     '&lsaquo;','&rsaquo;','&euro;','&nbsp;','&iexcl;','&cent;','&pound;',
  84.     '&curren;','&yen;','&brvbar;','&sect;','&uml;','&copy;','&ordf;',
  85.     '&laquo;','&not;','&shy;','&reg;','&macr;','&deg;','&plusmn;','&sup2;',
  86.     '&sup3;','&acute;','&micro;','&para;','&middot;','&cedil;','&sup1;',
  87.     '&ordm;','&raquo;','&frac14;','&frac12;','&frac34;','&iquest;','&Agrave;',
  88.     '&Aacute;','&Acirc;','&Atilde;','&Auml;','&Aring;','&AElig;','&Ccedil;',
  89.     '&Egrave;','&Eacute;','&Ecirc;','&Euml;','&Igrave;','&Iacute;','&Icirc;',
  90.     '&Iuml;','&ETH;','&Ntilde;','&Ograve;','&Oacute;','&Ocirc;','&Otilde;',
  91.     '&Ouml;','&times;','&Oslash;','&Ugrave;','&Uacute;','&Ucirc;','&Uuml;',
  92.     '&Yacute;','&THORN;','&szlig;','&agrave;','&aacute;','&acirc;','&atilde;',
  93.     '&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;',
  94.     '&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;',
  95.     '&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&divide;','&oslash;',
  96.     '&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&yuml;',
  97.     '&fnof;','&Alpha;','&Beta;','&Gamma;','&Delta;','&Epsilon;','&Zeta;',
  98.     '&Eta;','&Theta;','&Iota;','&Kappa;','&Lambda;','&Mu;','&Nu;','&Xi;',
  99.     '&Omicron;','&Pi;','&Rho;','&Sigma;','&Tau;','&Upsilon;','&Phi;','&Chi;',
  100.     '&Psi;','&Omega;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;',
  101.     '&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;',
  102.     '&xi;','&omicron;','&pi;','&rho;','&sigmaf;','&sigma;','&tau;',
  103.     '&upsilon;','&phi;','&chi;','&psi;','&omega;','&thetasym;','&upsih;',
  104.     '&piv;','&bull;','&hellip;','&prime;','&Prime;','&oline;','&frasl;',
  105.     '&weierp;','&image;','&real;','&trade;','&alefsym;','&larr;','&uarr;',
  106.     '&rarr;','&darr;','&harr;','&crarr;','&lArr;','&uArr;','&rArr;','&dArr;',
  107.     '&hArr;','&forall;','&part;','&exist;','&empty;','&nabla;','&isin;',
  108.     '&notin;','&ni;','&prod;','&sum;','&minus;','&lowast;','&radic;','&prop;',
  109.     '&infin;','&ang;','&and;','&or;','&cap;','&cup;','&int;','&there4;',
  110.     '&sim;','&cong;','&asymp;','&ne;','&equiv;','&le;','&ge;','&sub;','&sup;',
  111.     '&nsub;','&sube;','&supe;','&oplus;','&otimes;','&perp;','&sdot;',
  112.     '&lceil;','&rceil;','&lfloor;','&rfloor;','&lang;','&rang;','&loz;',
  113.     '&spades;','&clubs;','&hearts;','&diams;'
  114.   );
  115.  
  116.   $string = str_replace($entities, $unicode, $string);
  117.  
  118.   return $string;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement