1

I've created simple PHP script that gets content of file. After iconv function is changing encoding to UTF-8. Everything is working correctly on my localhost (PHP 7). Problem is that it isn't working on website with PHP 5.5.21 installed. I really need to fix it so it will work on 5.5.21 too.

iconv(): Detected an illegal character in input string in FILE-PATH

Code that isn't working on 5.5 but is on 7:

$file = file_get_contents($_FILES['csvfile']['tmp_name']);
$c = iconv(iconv_get_encoding($file),"UTF-8",$file);

Iconv on PHP7 enter image description here Iconv on PHP5.5 enter image description here

File to convert: enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
UareBugged
  • 178
  • 1
  • 11
  • Check if anything comes of using error reporting http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner May 02 '16 at 14:50
  • "iconv(): Detected an illegal character in input string in FILE-PATH" – UareBugged May 02 '16 at 14:52
  • Try explicitly configuring the iconv encoding values in your php.ini – Mark Baker May 02 '16 at 14:54
  • *Hm...*, maybe a hidden character such as a zero byte uuencode? show us what var_dump reveals. – Funk Forty Niner May 02 '16 at 14:54
  • problem is that I don't have access to php.ini on that system which has 5.5.21PHP – UareBugged May 02 '16 at 14:55
  • I've added image of file to my post – UareBugged May 02 '16 at 14:57
  • check the file's encoding if it's UTF-8 with or without BOM. See http://stackoverflow.com/questions/279170/utf-8-all-the-way-through could be related. – Funk Forty Niner May 02 '16 at 14:58
  • It's CSV file made from excel file. yea I can make that everytime i will directly in notepad++ convert whole file to utf-8 but problem is that the person I'm doing this for doesn't know what notepad++ is so i must automatically convert that CSV file in PHP script – UareBugged May 02 '16 at 15:01
  • Also, notepad++ is showing ANSI as the file encoding when I open the file in notepad++ – UareBugged May 02 '16 at 15:02
  • ok, then it's a file encoding issue, far as I can tell. Can you test this by saving it as UTF-8, and with and without BOM? If it works and no errors, then you'll have a fairly good idea as to what to go after. I wish I could help you more, but that is the scope of my knowledge on this one. @UareBugged – Funk Forty Niner May 02 '16 at 15:04

0 Answers0