PHP file () returns (unknown char) between each letter

0

I am doing file () to a file and it returns between each letter of the document.

alfa.dic

Adão
Andy

Code:

$dictionary = file('alfa.dic', FILE_IGNORE_NEW_LINES);

var_dump:

string '�A�d�ã�o�' (length=9)
string '�A�n�d�y�' (length=9)

I thought it was a charset problem but even using utf8_encode() this does not remove the characters.

How can I clean each line of these unknown characters?

    
asked by anonymous 09.09.2014 / 18:37

1 answer

2

The question of @gabrielhof helped me to realize that the problem was the charset of the file being 'UTF-16 LE with BOM' instead of UTF8 .

Using the Sublime Text 3 editor I went to

File -> Save with Encoding -> UTF8

And the problem was solved for communication with PHP. Thanks

    
09.09.2014 / 19:21