0

I'm trying to encode a string that contains accented uppercase letter like:

$string = "This is a test - À ";

i'm trying to encode using utf8_encode in this way:

$string  = "This is a test - À ";
$encoded = utf8_encode($string);

And returned string is:

"This is a test - ã ";

What function can i use instead utf8_encode ?

EDIT

This string is stored into a table in mysql db.

This is how i connect to database:

$host = "xxxxxx:3306";
$uid =  "username";
$pwd =  "password";
$dv_database_name = "db_name";

$db_dv = mysql_connect($host, $uid, $pwd);

mysql_query("SET NAMES utf8",$db_dv);
$sql = "...";
$res = mysql_query($sql, $db_dv);
$row = mysql_fetch_array($res);
$string = $row['myField']; // THIS IS THE STRING WITH ACCENTED VALUE
Charles
  • 50,943
  • 13
  • 104
  • 142
Jayyrus
  • 12,961
  • 41
  • 132
  • 214

1 Answers1

1

I suppose the problem is with your original string: are you sure the editor you edit it with is in utf8 mode?
utf8_encode() is only capable to transcode from ISO-8859-1 to UFT8

I see your code. I would suggest to follow directions in the comments to your question. No need to use utf8_encode, if everything is already UTF8.

Be sure that html page presenting the results to the user has explictit UTF8 encoding (as suggested by Peter).

Charles
  • 50,943
  • 13
  • 104
  • 142
MarcoS
  • 17,323
  • 24
  • 96
  • 174
  • Sorry but the string is stored into mysql in utf8. Using GUI db editor i show string correctly – Jayyrus Mar 27 '14 at 13:28
  • So please show the code you use to connect to db and to extract the data (hiding passwords, of course... :-) – MarcoS Mar 27 '14 at 13:29