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?

0

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answer but still not working :( <?php if(isset($_POST['myname'])) { $name = $_POST['myname']; $handle = fopen('names.csv', 'a'); ob_end_clean(); ob_start(); fwrite($handle, $name."\n"); fclose($handle); } ?>
-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

3 Comments

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: malatvornicakreative.hr/baza/proba
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.
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 -.-

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.