I'm a beginner in PHP.
I am currently preparing a questionnaire form.
アンケート Fill in the questionnaire
②Input Confirmation Form
③Answer completion page (at this point the questionnaire will be printed in a CSV file)
④Read and view CSV files here page for answers
This is the configuration.
As of 3
// Preparing to write an array to a csv file
$title=['Name', 'Attendance Number', 'Email Address', 'Gender', 'Hobby', 'Last Year's Best Memories', 'Resolution of the Year'];
$vararray = [$myid, $number, $mail, $gender, $hobby, $lastyear, $thisyear];
// Convert string from UTF-8
mb_convert_variables('SJIS-win', 'UTF-8', $title);
mb_convert_variables('SJIS-win', 'UTF-8', $vararray);
// Write to file
$handle=fopen('data/data.csv', 'a');
block($handle,LOCK_EX);
fputcsv($handle,$title);
fputcsv($handle,$vararray);
block($handle,LOCK_UN);
fclose($handle);
The code has been written to the csv file successfully.
At this time, I changed the encoding from UTF-8 to Shift_JIS, so when I read in で, the characters get garbled.
When I changed the encoding to Shift_JIS in my browser, the garbled characters disappeared, so when I read it, I understood that it was encoded as Shift_JIS, but I don't know how to return it to UTF-8.
First mb_convert_variables ('SJIS-win', 'UTF-8', $ variable);
I thought I should change it in
but the situation hasn't changed.
setlocale(LC_ALL,'ja_JP.UTF-8');
also tried, but it didn't work here
Currently, the code below is not working.
<?php
setlocale(LC_ALL, 'ja_JP.UTF-8');
$fp = fopen("data/data.csv", "r"); // Open File
US>block($fp,LOCK_SH);// File Lock
while($array=fgetcsv($fp)){// Load file
$num = count($array); // line count
for($i=0;$i<$num;$i++){
echo'<p style="font-size:12px;">'.$array[$i].'</p>';// Output for now
}
}
block($fp,LOCK_UN);// Unlock
fclose($fp);// Close file
?>
If you know anything about it, please let me know.
Thank you for your cooperation.
php csv array
According to http://php.net/manual/ja/function.mb-convert-variables.php,
string mb_convert_variables (string$to_encoding, mixed$from_encoding, mixed&$vars[, mixed&$...])
So, isn't it mb_convert_variables ('UTF-8', 'SJIS-win', $ variable);
?
© 2024 OneMinuteCode. All rights reserved.