4

i have this php file that connect to my MySQL BD , the BD callation is latin1_swedish_ci

this is my php code:

<?php

$con = mysql_connect("localhost","root","");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("ttbfb", $con);

$result = mysql_query("SELECT * FROM news");

while($row = mysql_fetch_array($result)) {

    echo $row['name'];

}

mysql_close($con);
?>

how can i convert the $row['name'] string into utf8 before i get the echo ?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
aLFaRSi
  • 559
  • 2
  • 12
  • 29
  • what's the matter you got when `echo $row['name']` – Ta Duy Anh Oct 17 '12 at 16:39
  • 2
    Consider using `mysql_query("SET NAMES utf8")` right after connecting to your database. – Ofir Baruch Oct 17 '12 at 16:42
  • @OfirBaruch i did right after mysql_select_db("ttbfb", $con); but still didnt change the string to anything – aLFaRSi Oct 17 '12 at 16:46
  • For those concerned about whether this is a duplicate, even though it seems to want to do the conversion in the opposite direction: note that the other question has "and back" in the title, which means that it is broader and covers *both* directions of conversion. Also note that the answer here simply links to the other Q&A... – Cody Gray - on strike Nov 18 '21 at 13:25
  • how to convert "सूगी, पोखरी तहसील में भारत à¤" characters to unicode human readable please suggest. – Harinarayan Apr 11 '22 at 11:16

1 Answers1

4

Options for converting encodings are provided in Convert utf8-characters to iso-88591 and back in PHP

Community
  • 1
  • 1
gapple
  • 3,463
  • 22
  • 27