Try this:
$df = fopen($filepath, 'w');
fprintf($df, chr(0xEF).chr(0xBB).chr(0xBF));
fputcsv($df, array($coupon->code, $discount->label));
the line fprintf($df, chr(0xEF).chr(0xBB).chr(0xBF));
writes file header for correct encoding.
Related Contents:
- Detect encoding and make everything UTF-8
- PHP output showing little black diamonds with a question mark
- How can I get a hex dump of a string in PHP?
- How to replace Microsoft-encoded quotes in PHP
- Error: “Input is not proper UTF-8, indicate encoding !” using PHP’s simplexml_load_string
- What is the best collation to use for MySQL with PHP? [closed]
- PHP DOMDocument loadHTML not encoding UTF-8 correctly
- Why does the PHP json_encode function convert UTF-8 strings to hexadecimal entities?
- How do I remove  from the beginning of a file?
- PHP: Convert any string to UTF-8 without knowing the original character set, or at least try
- What is the equivalent of JavaScript’s encodeURIcomponent in PHP?
- ucfirst() function for multibyte character encodings
- What is the difference between iconv() and mb_convert_encoding() in PHP?
- PHP json encode – Malformed UTF-8 characters, possibly incorrectly encoded [duplicate]
- Getting ’ instead of an apostrophe(‘) in PHP
- Base64 Encoding Image
- Why is base64_encode() adding a slash “/” in the result?
- Decode gzipped web page retrieved via cURL in PHP
- How to convert these strange characters? (ë, Ã, ì, ù, Ã)
- Convert latin1 characters on a UTF8 table into UTF8
- json_encode(): Invalid UTF-8 sequence in argument
- Email from PHP has broken Subject header encoding
- How can I write a file in UTF-8 format?
- Convert utf8-characters to iso-88591 and back in PHP
- utf8mb4_unicode_ci vs utf8mb4_bin
- PHP decoding and encoding json with unicode characters
- How do you parse and process HTML/XML in PHP?
- Are PHP short tags acceptable to use?
- Get the client IP address using PHP [duplicate]
- Remove portion of a string after a certain character
- Show a PDF files in users browser via PHP/Perl
- CodeIgniter: How to get Controller, Action, URL information
- How to compare two dates in php [duplicate]
- PHP json_decode() returns NULL with seemingly valid JSON?
- Why is it bad to have a weak mysql user password?
- Add a prefix to each item of a PHP array
- PHP get domain name [duplicate]
- How to check if time is between two times in PHP [duplicate]
- No hint path defined for [mail] Laravel 5.4
- PHP Fatal error: Call to undefined function curl_init()
- What is a class in PHP?
- How can I call a static method from a class if all I have is a string of the class name?
- How to parse JSON and access results
- PHPMailer generates PHP Warning: stream_socket_enable_crypto(): Peer certificate did not match expected
- The requested PHP extension dom is missing from your system
- Check if a string contains nothing but an URL in PHP
- How to create a foreign key in phpmyadmin
- How to get current logged in user using WordPress Rest Api?
- How to read the response effective URL in Guzzle ~6.0
- RegExp to strip HTML comments