php 如何把中文写入json中 当json文件中还显示的是中文

/***
     * 更新版本
     */
    function showupversionsub(){
        
        #接受post 过来的数据
        $app_type=$_POST['aap_type'];
        if($app_type=='android'||$app_type=='ios'||$app_type=='windows'){
            #组成数组
            $arr=array(
            mainVer=>$_POST['mainVer']==null? '':$_POST['mainVer'],
            upVer=>$_POST['upVer']==null? '':$_POST['upVer'],
            upTips=>$_POST['upTips']==null? '':$_POST['upTips'],
            assetPath=>$_POST['assetPath']==null? '':$_POST['assetPath'],
            newUpiniPath=>$_POST['newUpiniPath']==null? '':$_POST['newUpiniPath'],
            appStore=>$_POST['appStore']==null? '':$_POST['appStore'],
            forceUpdateVersion=>$_POST['forceUpdateVersion']==null? '' :$_POST['forceUpdateVersion']    
            );
            #转化成JSON字符串(兼容中文)
            $str = json_encode($arr);
            $search = "#\\\u([0-9a-f]{1,4}+)#ie";
            $replace = "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))";
            $text=preg_replace($search, $replace, $str);
            #文件路径
            $url="D:/WWW/gm_lequ/gm_lequ/".$app_type.'/update.ini';
            #判断文件的路径是否存在 判断目录是否存在我们用is_dir就OK了。
            if(file_exists($url)){
                $fp=fopen($url, "w+");
                #文件加锁防止多个人同时写入文件
                if(flock($fp, LOCK_EX)){
                    #写入内容
                    fwrite($fp, $text);
                    #文件解锁
                    flock($fp, LOCK_UN);
                    $this->PromptMsg = "更新成功!";
                }else{
                    $this->PromptMsg = "正在写入文件中...请稍等!";
                }
            }else{
                $this->PromptMsg = "文件路径不存在";
            }
        }
        
        $this->UrlJump = "index.php?module=operation&action=upversion&menuId=166";
        $this->promptMsg ();
        
    }

 

转载于:https://www.cnblogs.com/hgj123/p/4495702.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值