Welcome Guest, Not a member yet? Register   Sign In
ascii_to_entities
#1

[eluser]jeffpeck[/eluser]
I noticed that the ascii_to_entities function was not working properly converting things like smart quotes and TM symbols, so I modified the code by reducing it to something a lot simpler than it originally was. The following is my new implementation and it seems to just work. Does anybody know why it was originally more complicated.

It seemed that in the previous version it would treat any character code of ASCII code 224 or higher to be of length 2, which did not seem to be the case for the single quote that was I was using, which is ’

Anyway, if anybody is having similar issues try replacing the function with this.

Code:
function ascii_to_entities($str)
{
   $count    = 1;
   $out    = '';
   $temp    = array();
  
   for ($i = 0, $s = strlen($str); $i < $s; $i++)
   {
       $ordinal = ord($str[$i]);
      
       if ($ordinal < 128)
          $out .= $str[$i];
       else
          $out .= '&#'.$ordinal.';';
   }
}




Theme © iAndrew 2016 - Forum software by © MyBB