-1

I have some french words in a table and I want to display each of them character by character. However, when using str_split or any other way of converting the string into array (like $string[$i]), the accented characters are not showing at all.

On the other hand if I output the string directly, the accented characters are displaying correctly.

Example:

echo "Québec" outputs Québec (correct)

str_split("Québec") outputs Q u b e c (issue)

The above indicates that it's not an encoding issue. I have also tried htmlentities($string, 0, 'UTF-8') in order to have HTML-safe characters but now when splitting html entities I get the following:

str_split(htmlentities("Québec", 0, 'UTF-8')) outputs Q u & e a c u t e ; b e c (issue)

How can I display each character separately but displaying accented characters correctly?

otinanai
  • 3,987
  • 3
  • 25
  • 43

1 Answers1

1

According to the documentation (http://php.net/str_split) , you could use str_split_unicode() built in the first example. The first example on the page refers to that.

Hozikimaru
  • 1,144
  • 1
  • 9
  • 20
  • I feel stupid for haven't noticed this function and I was searching for hours before posting my question. Thank you! – otinanai Apr 08 '15 at 21:17