简体   繁体   中英

Encoding issue with japanese character in php

Im using php and slickgrid to show a datagrid structure..everything works fine.but my site is multilanguage when i change to japanese language..i have this error on the java script side ,the data is send from php as json

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

I have done utf8_encode and htmlspecialchars for the content.but still it is breaking

How to properly encode japanese character with php

data im getting from php side for 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 }

Update for @pekka Code on the Php side

 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

Thanks all..i got the answer i used this function

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM