符号在数据库中正确保存,但在视图中显示符号时,符号无法正常显示。
保存在数据库中的数据:
<p>Symbol here is sigma : Σ</p>
<p>Symbol here is beta: β</p>
<p>Symbol here is omega: Ω</p>
<p>Symbol here is gamma: γ</p>
正在显示的数据:
Symbol here is sigma : Σ
Symbol here is beta: β
Symbol here is omega: Ω
Symbol here is gamma: γ
获取数据的代码:
public function get_questions() {
$this->layout = false;
if(($this->request->is('post')) && ($this->request->is('ajax'))) {
$subject = $this->request->data['subject'];
$chapter = $this->request->data['chapter'];
$studentID = $this->Auth->User('PERSONROLE');
//$phase = $subject->getPhase($subject);
$this->Paginator->settings = array(
'limit' => 1,
'conditions' => array(
'QuestionBank.SUBJECT' => $subject,
'QuestionBank.CHAPTER' => $chapter,
'QuestionBank.IS_ACTIVE' => 1,
//'QuestionBank.PHASE'
),
);
$questions = $this->paginate();
if($questions) {
$questions[0]['QuestionBank']['page'] = $this->request->params['paging']['QuestionBank']['page'];
$questions[0]['QuestionBank']['current'] = $this->request->params['paging']['QuestionBank']['current'];
$questions[0]['QuestionBank']['count'] = $this->request->params['paging']['QuestionBank']['count'];
$questions[0]['QuestionBank']['prevPage'] = $this->request->params['paging']['QuestionBank']['prevPage'];
$questions[0]['QuestionBank']['nextPage'] = $this->request->params['paging']['QuestionBank']['nextPage'];
$questionID = $questions[0]['QuestionBank']['ID'];
$selfStudyStatus = $this->_getQuestionStatus($questionID, $studentID);
if($selfStudyStatus) {
$questions[0]['SelfStudyStatus'] = $selfStudyStatus['SelfStudy'];
}
$this->loadModel('MyNote');
$myNote = new MyNote();
$notes = $myNote->getPersonalNote($questionID, $studentID);
if($notes) {
$questions[0]['MyNote'] = $notes['MyNote'];
} else {
$questions[0]['MyNote'] = array();
}
$this->loadModel('Enquiry');
$enquiry = new Enquiry();
$enquiries = $enquiry->getEnquiries($studentID, $questionID);
if($enquiries) {
$questions[0]['Enquiry'] = $enquiries;
} else {
$questions[0]['Enquiry'] = array();
}
}
array_walk_recursive($questions, function(&$value, $key) {
if (is_string($value)) {
$value = iconv('windows-1252', 'utf-8', $value);
}
});
$this->set('questions', $questions[0]);
}
}
请检查上面的代码,这行是“$ value = iconv('windows-1252','utf-8',$ value);”必须对转换做点什么。 charset转换对我来说是新的。