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 2 of 2
  1. #1
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts

    char encode function

    hi all just wrote this:

    PHP Code:
    <?php

    function unicodeConvert($str)
    {
        
    header('Content-Type:text/html; charset=UTF-8');
        
    $entityRef = array('"' => "&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;");
        
        foreach(
    $entityRef as $key => $obj)
        {
            if(
    $key!="&")
            {
                
    $str str_replace($key$obj$str);
            }
            else
            {
                
    $str preg_replace("#&((?!(amp;)|(igrave;)|(laquo;)|(Ugrave;)))#is"" ".$obj." "$str);    
            }
        }
        return 
    $str;
    }

    echo 
    unicodeConvert("i want pies &&&& poo but not  &amp; &igrave; &Ugrave; && && &");

    ?>
    viewSource:
    Code:
    i want pies  &amp;  &amp;  &amp;  &amp;  poo but not &laquo; &amp; &igrave; &Ugrave;  &amp;  &amp;   &amp;  &amp;   &amp;
    output to browser:
    Code:
    i want pies & & & & poo but not  &   & & & & &
    problem being, it adds a space on the end of some &amp. can anyone see why?
    Last edited by Phil Jackson; 10-20-2009 at 12:40 AM.
    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(); 

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    im too tiered sorted it now
    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
    •