Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts

    unicode entity reference convert

    PHP Code:
    <?php
    # www.actwebdesigns.co.uk
    # luke@actwebdesigns.co.uk
    #
    # This should help towards a better encoding option;
    # echo unicodeConvert("i want pies &&&& poo but not  &amp; &igrave; &Ugrave; &&amp;nbsp;& && &");
    # echo "<br />".htmlentities("i want pies &&&& poo but not  &amp; &igrave; &Ugrave; && && &");
    # echo "<br />".html_entity_decode("i want pies &&&& poo but not  &amp; &igrave; &Ugrave; && && &");
    #
    # Would output to the browser:
    #
    # i want pies &&&& poo but not  &   & & && &
    # i want pies &&&& poo but not « &amp; &igrave; &Ugrave; && && &
    # i want pies &&&& poo but not  & � � && &&
    #
    # Source code would be;
    #
    # i want pies &amp;&amp;&amp;&amp; poo but not &laquo; &amp; &igrave; &Ugrave; &amp;&nbsp;&amp; &amp;&amp; &amp;
    # <br />i want pies &amp;&amp;&amp;&amp; poo but not &Acirc;&laquo; &amp;amp; &amp;igrave; &amp;Ugrave; &amp;&amp; &amp;&amp; &amp;
    # <br />i want pies &&&& poo but not  & � � && && 
    #
    # enjoy!

    function unicodeConvert($str)
    {
        
        
    header('Content-Type:text/html; charset=UTF-8');
        
    $entityRef = array("&" => "&amp;"'' => "&cent;"'' => "&curren;"'' => "&brvbar;"'' => "&uml;"'' => "&ordf;"'' => "&not;"'' => "&reg;"'' => "&deg;"'' => ""'' => "&acute;"'' => "&para;"'' => "&cedil;"'' => "&ordm;"'' => ""'' => ""'' => "&Agrave;"'' => "&Acirc;"'' => "&Auml;"'' => "&AElig;"'' => "&Egrave;"'' => "&Ecirc;"'' => "&Igrave;"'' => "&Icirc;"'' => "&ETH;"'' => "&Ograve;"'' => "&Ocirc;"'' => "&Ouml;"'' => "&Oslash;"'' => "&Uacute;"'' => "&Uuml;"'' => "&THORN;"'' => "&agrave;"'' => "&acirc;"'' => "&auml;"'' => "&aelig;"'' => "&egrave;"'' => "&ecirc;"'' => "&igrave;"'' => "&icirc;"'' => "&eth;"'' => "&ograve;"'' => "&ocirc;"'' => "&ouml;"'' => "&oslash;"'' => "&uacute;"'' => "&uuml;"'' => "&thorn;"'' => "&iexcl;"'' => "&pound;"'' => "&yen;"'' => "&sect;"'' => "&copy;"'' => "&laquo;"'' => "&macr;"'' => "&plusmn;"'' => ""'' => "&micro;"'' => "&middot;"'' => ""'' => "&raquo;"'' => ""'' => "&iquest;"'' => "&Aacute;"'' => "&Atilde;"'' => "&Aring;"'' => "&Ccedil;"'' => "&Eacute;"'' => "&Euml;"'' => "&Iacute;"'' => "&Iuml;"'' => "&Ntilde;"'' => "&Oacute;"'' => "&Otilde;"'' => "&times;"'' => "&Ugrave;"'' => "&Ucirc;"'' => "&Yacute;"'' => "&szlig;"'' => "&aacute;"'' => "&atilde;"'' => "&aring;"'' => "&ccedil;"'' => "&eacute;"'' => "&euml;"'' => "&iacute;"'' => "&iuml;"'' => "&ntilde;"'' => "&oacute;"'' => "&otilde;"'' => "&divide;"'' => "&ugrave;"'' => "&ucirc;"'' => "&yacute;"'' => "&yuml;");
        
        foreach(
    $entityRef as $key => $obj)
        {
            if(
    $key!="&")
            {
                
    $str str_replace($key$obj$str);
            }
            else
            {
                
    $str preg_replace("#&((?!(quot;)|(amp;)|(cent;)|(curren;)|(brvbar;)|(uml;)|(ordf;)|(not;)|(reg;)|(deg;)|(sup2;)|(acute;)|(para;)|(cedil;)|(ordm;)|(frac14;)|(frac34;)|(Agrave;)|(Acirc;)|(Auml;)|(AElig;)|(Egrave;)|(Ecirc;)|(Igrave;)|(Icirc;)|(ETH;)|(Ograve;)|(Ocirc;)|(Ouml;)|(Oslash;)|(Uacute;)|(Uuml;)|(THORN;)|(agrave;)|(acirc;)|(auml;)|(aelig;)|(egrave;)|(ecirc;)|(igrave;)|(icirc;)|(eth;)|(ograve;)|(ocirc;)|(ouml;)|(oslash;)|(uacute;)|(uuml;)|(thorn;)|(iexcl;)|(pound;)|(yen;)|(sect;)|(copy;)|(laquo;)|(macr;)|(plusmn;)|(sup3;)|(micro;)|(middot;)|(sup1;)|(raquo;)|(frac12;)|(iquest;)|(Aacute;)|(Atilde;)|(Aring;)|(Ccedil;)|(Eacute;)|(Euml;)|(Iacute;)|(Iuml;)|(Ntilde;)|(Oacute;)|(Otilde;)|(times;)|(Ugrave;)|(Ucirc;)|(Yacute;)|(szlig;)|(aacute;)|(atilde;)|(aring;)|(ccedil;)|(eacute;)|(euml;)|(iacute;)|(iuml;)|(ntilde;)|(oacute;)|(otilde;)|(divide;)|(ugrave;)|(ucirc;)|(yacute;)|(yuml;)|(nbsp;)|(lt;)|(gt;)))#is"$obj$str);    
            }
        }
        return 
    $str;
    }

    ?>
    Last edited by Phil Jackson; 10-20-2009 at 04:06 PM.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •