1

I have a column in a database called Name I'm doing an echo() on this column to show the value (simple knowledge)

When doing an var_dump on the mySQL row, I'm shown the following

["Name"]=> string(10) "Marko Baša"

If I go ahead and do echo $Name I'm shown the following

Marko Baa

But then, If I go ahead and do a utf8_encode arround it, it appears a little better

Marko Baša

How could I get it to display like so

Marko Basa
Curtis
  • 2,646
  • 6
  • 29
  • 53
  • If you're looking to replace `š` with `s`, then you're looking for [transliteration](http://stackoverflow.com/questions/13614622/transliterate-any-convertible-utf8-char-into-ascii-equivalent) –  May 28 '14 at 16:43
  • `š` and `s` are different characters - I'm thinking you just need to use `str_replace`. – Brilliand May 28 '14 at 16:45
  • check http://www.php.net/manual/en/mysqli.set-charset.php will help you out – fortune May 28 '14 at 16:45
  • possible duplicate of [How to remove accents and turn letters into "plain" ASCII characters?](http://stackoverflow.com/questions/3542717/how-to-remove-accents-and-turn-letters-into-plain-ascii-characters) – Brilliand May 28 '14 at 17:04
  • There are several questions on this topic, but the question I just linked to seems to have the best answers of the ones I've found (despite being marked as a duplicate itself). – Brilliand May 28 '14 at 17:06

3 Answers3

1

Set your charset in the HTML:

<head>
<meta charset="UTF-8">
</head>

The browser is apparently not interpreting your page as UTF-8 by default.

Brilliand
  • 13,404
  • 6
  • 46
  • 58
1

Use iconv to transliterate:

echo iconv('UTF-8', 'ASCII//TRANSLIT', 'Marko Baša');
Brilliand
  • 13,404
  • 6
  • 46
  • 58
  • When using that, it doesn't display anything? – Curtis May 28 '14 at 16:50
  • Replace `UTF-8` with your actual charset? It works for me, but my scripts are actually saved in UTF-8. Alternately, you could `utf8_encode` the string before passing it to `iconv` (looking at the documentation, it seems that converts from `ISO-8859-1`). – Brilliand May 28 '14 at 16:53
0

You can try:

header('Content-Type: text/html; charset=utf-8');
Jeroen
  • 15,257
  • 12
  • 59
  • 102
  • @KateGregory It works for essentially the same reason as `` - and fails to answer this question for exactly the same reason. – Brilliand May 28 '14 at 17:32