我已导出到export.php中的csv函数。 功能正常。只是日文字符的显示如下所示:‰∫àÁ¥ÑÊΠà“Åø 当我在页面和csv文件中回显变量时。
charset已经是UTF-8。 它在其他页面中显示正常。 我不知道下一步该做什么。
这是我的代码:
public function excel()
{
$student_id = $_GET['student_id'];
$lesson = &Chico::getInstance('Controller_Frontend_Lesson');
$defaults = &Chico::getInstance('Model_Defaults');
$get_lesson_history = $lesson->lesson_history(get_user_meta($student_id, 'gge_access_token', true));
$convert_lesson_time = $lesson->convert_lesson_time($get_lesson_history);
$lesson_history = $lesson->sort_history($convert_lesson_time);
$count = 1; $lesson_count = $this->get_lesson_count($lesson_history);
header('Content-Type: text/csv;charset=utf-8');
header(sprintf('Content-Disposition: attachment;Filename=%s.csv', get_user_meta($student_id, 'gge_name', true)));
$outstr = sprintf('PERIOD, %s ~ %s %s', !empty($_GET['begin']) ? $_GET['begin'] : 'Beginning', !empty($_GET['end']) ? $_GET['end'] : 'Present', "\n");
$outstr .= sprintf('STUDENT NAME, %s %s', get_user_meta($student_id, 'gge_name', true), "\n");
$outstr .= sprintf('SKYPE ID, %s %s', get_user_meta($student_id, 'gge_skype', true), "\n");
$outstr .= sprintf('NUMBER OF BOOKINGS, %s %s', $lesson_count, "\n");
$outstr .= sprintf('NUMBER OF LESSONS, %s %s', $lesson_count, "\n\n");
$outstr .= '#, DATE/TIME, TEACHER, STATUS, LESSON, REQUEST, COMMENT';
$outstr .= sprintf('%s', "\n");
if(!empty($lesson_history) && is_array($lesson_history)):
foreach ($lesson_history as $key => $value) {
$lastkey = count($value)-1;
$launched = strtotime($value[$lastkey]['launched']);
$datetime = sprintf('%s %2$s:00 ~ %2$s:50', date(__(get_option( 'date_format' )), $launched), date(__('H'), $launched));
if(strtotime($_GET['begin']) <= $launched && strtotime(sprintf('%s+1 days', $_GET['end'])) >= $launched):
$outstr.= join(',', array($count, $datetime,
$value[$lastkey]['teacher_name'],
$defaults::$status_ja[$value[$lastkey]['status']],
$value[$lastkey]['request_title'],
$value[$lastkey]['request_body'],
$value[$lastkey]['scores']['message']));
$outstr .= sprintf('%s', "\n");
$count++;
endif;
}
else:
$outstr.= join(',', 'No lesson history');
endif;
echo $outstr;
}
这是csv中的数据: 状态课程 SAMMY‰∫àÁ¥ÑÊΠà“Åø KREAN‰àà¥ÑÊΠà“Åø
答案 0 :(得分:2)
Excel默认使用windows-1252编码打开CSV文件。尝试使用文本编辑器或Open Office打开CSV文件(在其中可以选择字符集)。