Special characters display on HTML

UTF-8 specialchar to ASCII

Here is a simple PHP solution to special char display weirdly on html.

I have encountered this because Ajax somehow cannot pass utf-8 correctly.


function toascii($input){

$output = '';
$i = 0;

while($i< strlen($input)): if(ord($input[$i])>127):
$output .= '&#' . ord($input[$i]) . ';';
else:
$output .= $input[$i];
endif;

$i++;
endwhile;

return $output;
}

Leave a Reply