0

Can you plese help me with php fwrite. Csv showing wrong characters

something like:

općšpšćšćšp ćpšćpšćp šćpšćpšć

This is php code for input:

I can't find option to fix UTF-8 for this php:

<?php
if (isset($_POST['myname'])){
$name = $_POST['myname'];
$handle = fopen('names.csv', 'a');
fwrite($handle, $name."\n");
fclose($handle); }

?>

Html:

    <form method="post" action="demo.php">

   Myname: <input type="text" name="myname" /> 

   <input type="submit" name="submit" value="submit data" />
   </form>

Somebody help please?

TNX
  • 23
  • 1
  • 8

2 Answers2

0

If it is UFT-8 decoding issue, you can follow links in the comments section. In my case,I was generating .cvs file in laravel framework, I got that Issue. I just added the Following code before fwrite, my problem was solved.

You can try Following before:

ob_end_clean();
ob_start();
fwrite($handle, $name."\n");
fclose($handle); 

Which "Clean (erase) the output buffer and turn off output buffering" as per the Link

-1

seems that your encoding is wrong. you can convert it by using iconv or utf-encode on $name.

for broken utf8-strings, have a look at ForceUTF8

meistermuh
  • 393
  • 3
  • 11
  • This is for html input, i'am trying to make input that save all data to .csv. I'am new in php and i don't know where to put iconv code :( to encode utf: this is an example: http://malatvornicakreative.hr/baza/proba/ – TNX Mar 28 '18 at 12:26
  • This is not an answer, this is a comment. If you can't post comments yet, gain more reputation first. Please don't bypass the system. – eisbehr Mar 28 '18 at 12:31
  • his/her problem is wrong encoding (as **clearly** shown in the example) and the functions given in my answer would solve that. adding legit questions should not be a problem! so it INDEED IS an answer. I edited it to make it clear. If you still not accept it...thanks for not understanding -.- – meistermuh Mar 28 '18 at 12:50