Jump to content

Recommended Posts

I wish to load some Chinese characters into a csv file, however the following code only works with English words, anyone knows how to change the code so it works with Chinese characters? :shrug:

 

Many thanks,

Cat

 

 

$pfw_file_name = "registration.csv";

$pfw_first_row = "title,First Name,Last Name,Job Title,Company,Email,Telephone Number,Fax Number,Address 1,Address 2,City,County,Postcode,Country,ID,Other\r\n"; //Content-type: text/html; charset=utf-8\r\n

$pfw_values = "$title,$firstName,$lastName,$jobTitle,$company,$email,$tel,$fax,$address1,$address2,$city,$county,$postcode,$country,$id,$other\r\n";

 

$pfw_is_first_row = false;

if(!file_exists($pfw_file_name))

{

$pfw_is_first_row = true;

}

if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {

die("Cannot open file ($pfw_file_name)");

exit;

}

if ($pfw_is_first_row)

{

  if (fwrite($pfw_handle, $pfw_first_row ) === FALSE) {

  die("Cannot write to file ($pfw_filename)");

  exit;

  }

}

if (fwrite($pfw_handle, $pfw_values) === FALSE) {

  die("Cannot write to file ($pfw_filename)");

  exit;

}

fclose($pfw_handle);

 

Link to comment
https://forums.phpfreaks.com/topic/179949-how-to-use-php-set-csv-file-into-utf-8/
Share on other sites

read about utf8_encode in the manual should help

This function encodes the string data  to UTF-8, and returns the encoded version.

 

I tried, but it seems doesn't change anything.

i can view the Chinese characters in notepad, but if i open it in Excel, it becomes funny code

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.