0

Here is my doubt.

If I had this

$str = 'variável';

and I wanna use uft8_decode, the output is

variável

But if I had

$str = "variável"

I get

vari?vel

when I use utf8_decode

This is a problem when I send a file .txt, for example, that is already decoded, the output is "vari?vel" if I use utf8_decode.

The string $str is only an analogy. This is for a system where students send their homework that is a function in matlab, .m file, actually. A student sent the file for Linux and I found this problem.

I hope that I have been clear.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Klethonio
  • 41
  • 4
  • What are you decoding the utf8 to? – Sherif Aug 31 '16 at 01:10
  • So if I do ` – Perspective Aug 31 '16 at 01:11
  • Also ` $str = "variável"; echo utf8_decode($str)."\n";` outputs the correct `variável`, – Perspective Aug 31 '16 at 01:22
  • I see, you need to find away to identify if something needs to be encoded or not. – Perspective Aug 31 '16 at 01:30
  • Machavity, if you open the .txt file in another software are the results different. I noticed when I write to the .txt file and open with default text editor it's all messed up, if I open with `Atom` it looks a different way. – Perspective Aug 31 '16 at 01:39
  • If you use `iconv('utf-8', 'utf-8', $str)` this will fix your second problem, but it will then literally output `variável` so it will create a problem in your first scenario. – Perspective Aug 31 '16 at 02:08
  • 1
    This is will probably solve your problems https://github.com/neitanod/forceutf8 http://stackoverflow.com/questions/910793/detect-encoding-and-make-everything-utf-8 – Perspective Aug 31 '16 at 02:25

0 Answers0