在php中编码日语字符的问题

时间:2013-07-17 11:39:05

标签: php javascript unicode character-encoding escaping

我使用php和slickgrid显示数据网格结构..一切正常。但我的网站是多语言,当我改为日语..我在java脚本方面有这个错误,数据是从PHP发送为json

SyntaxError: unterminated string literal
{ id: "Lang_length", name: "最大値以上の長さ << error here

我已经为内容完成了utf8_encodehtmlspecialchars。但它仍在破坏

如何用php正确编码日语字符

数据即时php来自slickgrid

 var columns = [
{ id: "go_to", name: "è¡Œã", field: "go_to", formatter: htmlFormatter, sortable: true, width:100 },
{ id: "product_name", name: "製å“", field: "product_name", formatter: htmlFormatter, sortable: true, width: 400 },
{ id: "product_description", name: "記述", field: "product_description", formatter: htmlFormatter, sortable: true, width: 475 }

@pekka的更新 Php方面的代码

 if(strtolower($this->view->title)=="packaging materials")
            {
             $pahead_det = '{ id: "go_to", name: "' . PackAssist_Locale::translate('Go to') . '", field: "go_to", formatter: htmlFormatter, sortable: true,width: 75 },
                { id: "product_name", name: "' . PackAssist_Locale::translate('Group/Part') . '", field: "product_name", formatter: htmlFormatter, sortable: true, width: 400  },
                { id: "product_description", name: "' . PackAssist_Locale::translate('Description') . '", field: "product_description", formatter: htmlFormatter, sortable: true, width: 500  },';
            }else{
                $pahead_det = '{ id: "go_to", name: "' . PackAssist_Locale::translate('Go to') . '", field: "go_to", formatter: htmlFormatter, sortable: true, width: 75 },
                { id: "product_name", name: "' . PackAssist_Locale::translate('Group/Part') . '", field: "product_name", formatter: htmlFormatter, sortable: true, width: 400  },
                { id: "product_description", name: "' . PackAssist_Locale::translate('Description') . '", field: "product_description", formatter: htmlFormatter, sortable: true, width: 500  },';
            }

            if (strtolower($this->view->title) == "packaging materials") {

                $checkin = array();
                foreach ($mergearray as $m) {
                    if (isset($m['part_id'])) {
                        $getpropertyhead = $propertygrp_model->gridListPropertyHead($m['part_group_id']);
                        if (count($getpropertyhead) > 0) {
                            foreach ($getpropertyhead as $property) {
                                array_push($property_data_list, $property->pg_pd_id);
                                if (!in_array($property->pd_name_uniquename, $checkin)) {   //build the string with check to avoid redundancy
                                    $pahead_det .= '{ id: "' . $property->pd_name_uniquename . '", name: "' . $property->language_data_content . '", field: "' . $property->pd_name_uniquename . '", sortable: true, width: 150,formatter: htmlFormatter },';
                                }
                                array_push($checkin, $property->pd_name_uniquename);
                            }
                        }
                    }
                }
            }


            $this->view->pahead_det = substr($pahead_det, 0, -1); //header

1 个答案:

答案 0 :(得分:1)

谢谢大家......我得到了我使用此功能的答案

 public static function characterEscape($str) {
        return addcslashes($str, "\\\'\"&\n\r<>");
    }