16
Jun
Dealing with Ascii to ÛTF issue in PHP
By Joseph Montanez
0 Comment

Weird îssües

Probably seen that sort of character as well as other characters when pasting from M$ Word or even just save UTF to ascii into a database, then outputting the horrific characters. Well a good way to start is to make sure you specific utf in your html or php header.
<?php 
header('Content-Type: text/html; charset=UTF-8'); 
?>
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/> 
    <title>...</title>

</head>

Im Still Getting Wêïrd Characters

In php you can use str_replace, mix that with double quotes and you can replace any character.
<?php
// Replace  with &nbsp;
str_replace("\xC3\x82", '&nbsp;', $string);
?>

Uhhh How did you know \xC3\x82 is Â.

Well in Ubuntu I can use Applications > Accessories > Character Map and search for Â. Then clicking on the "Character Details" tab tells me that its "UTF-8: 0xC3 0x82" which is "\xC3\x82". If you dont have ubuntu you can go to Utf8 Chartable. There they show "c3 82" which is "\xC3\x82".

« Back to my notebook
Next Note > < Previous Note
Comment Pages: 1


esign