UTF-8转GBK编码问题,有什么好的解决方案? iconv需要加 IGNORE 参数,才能完成转换,不然会出错终止,而 mb_convert_encoding,是可以完成转换,但是转换出来的文件,有时候会出现中文注释替换成???。我开发的系统是UTF-8版本的,发布的时候需要转换出一个GBK版本,没有好的解决方案,求高手帮忙。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你能知道都是哪些字符不能被转换吗?知道了,才能有解决办法吧?你或许可以贴出一段包含不可转换字符的文字的 base64 编码 内容是不固定的,开发了一套utf8版本的PHP程序,然后整个目录转换成GBK,百度搜索了很多,应该是那个UTF8的空白分隔符是转不出GBK的 转换代码,保存为UTF8文件<?php$tmp = file_get_contents('utf8.php');$gbk = iconv('UTF-8', 'GBK//IGNORE', $tmp);file_put_contents('gbk.php', $gbk);$tmp = mb_convert_encoding($tmp, 'GBK', 'UTF-8');file_put_contents('gbk1.php', $tmp);echo 'success';?>utf8.php请保存为UTF8文件<?php// 文章模块控制器class ArticleAction extends BaseAction { protected function _initializeMore() { $this -> obj = M('article'); $this -> categoryObj = M('category'); $this -> assign('category', $this -> categoryObj -> categoryModule('article')); //设置标签类的栏目数组为当前模块栏目数组 } public function defaults() { $page = intval(R('page')); $pageSize = 20; $passed = R('passed') === ''?1:intval(R('passed')); $recycle = intval(R('recycle')); $where = array('recycle' => $recycle, 'passed' => $passed); $headline = R('headline'); $headline && $where['headline'] = 1; //头条信息 $elite = R('elite'); $elite && $where['elite'] = 1; //推荐信息 $ontop = R('ontop'); $ontop && $where['ontop'] = 1; //置顶信息 $catid = intval(R('catid')); if ($catid) { $tmp = $this -> categoryObj -> childAll($catid, C('isbigpost', 0, 'article'), true); $where[] = count($tmp) > 1?'catid IN (' . implode(', ', $tmp) . ')':'catid=' . intval(current($tmp)); } $q = R('q'); $q = trim(urldecode($q)); $q = Func :: FilterSearch($q); $this -> assign('q', $q); if ($q) { $q = explode(' ', $q); $or = array(); foreach($q as $word) { if ($word) { $or[] = "title LIKE '%$word%'"; $or[] = "keywords LIKE '%$word%'"; } } empty($or) or $where[] = $or; } $this -> assign('data', $this -> obj -> getList($page, $pageSize, $where, 'updatetime DESC, id DESC')); $this -> assign('pages', $this -> obj -> pages()); $this -> assign('catid', $catid); $this -> assign('passed', $passed); $this -> assign('recycle', $recycle); $this -> assign('headline', $headline); $this -> assign('elite', $elite); $this -> assign('ontop', $ontop); $this -> assign('jmpurl', '?' . del_query_string('catid|page|q')); $this -> assign('orderurl', '?' . del_query_string('order|field')); $this -> assign('order', strtoupper(R('order')) == 'DESC'?'ASC':'DESC'); $this -> display('article'); } // 审核通过 public function check() { if ($this -> obj -> setFields(array('checker' => get_cookie('username'), 'checktime' => TIME, 'passed' => 1))) $this -> showMsg(L('OPERATE_SUCCESS'), $this -> referer); else $this -> showMsg($this -> error); }}?>用两个不同的函数转换出的gbk文件,一个是去除了中文注释,一个是全部变成问号。 原来我错了,原来文件保存的是ANSI编码的,再转换才出现了这样的问题 php开发web网站,有几个问题请教 求一个复杂的时间格式转换函数 PHP流程控制练习代码 请教一下类的问题 php如何得到http://url/dir/的内容,类似opendir 查询9天内的数据!!SQL语句咋整!! dba_open() 未定义是什么回事?? 问大家一个关于 下载的问题,100 在线等带 问下svn的常识问题 大神啊,这个PHP代码什么解密? 又是正则....谢谢啊。。。 循环执行执行不了。
知道了,才能有解决办法吧?你或许可以贴出一段包含不可转换字符的文字的 base64 编码
$tmp = file_get_contents('utf8.php');
$gbk = iconv('UTF-8', 'GBK//IGNORE', $tmp);
file_put_contents('gbk.php', $gbk);
$tmp = mb_convert_encoding($tmp, 'GBK', 'UTF-8');
file_put_contents('gbk1.php', $tmp);
echo 'success';
?>
utf8.php请保存为UTF8文件<?php
// 文章模块控制器
class ArticleAction extends BaseAction {
protected function _initializeMore() {
$this -> obj = M('article');
$this -> categoryObj = M('category');
$this -> assign('category', $this -> categoryObj -> categoryModule('article')); //设置标签类的栏目数组为当前模块栏目数组
}
public function defaults() {
$page = intval(R('page'));
$pageSize = 20;
$passed = R('passed') === ''?1:intval(R('passed'));
$recycle = intval(R('recycle'));
$where = array('recycle' => $recycle, 'passed' => $passed);
$headline = R('headline');
$headline && $where['headline'] = 1; //头条信息
$elite = R('elite');
$elite && $where['elite'] = 1; //推荐信息
$ontop = R('ontop');
$ontop && $where['ontop'] = 1; //置顶信息
$catid = intval(R('catid'));
if ($catid) {
$tmp = $this -> categoryObj -> childAll($catid, C('isbigpost', 0, 'article'), true);
$where[] = count($tmp) > 1?'catid IN (' . implode(', ', $tmp) . ')':'catid=' . intval(current($tmp));
}
$q = R('q');
$q = trim(urldecode($q));
$q = Func :: FilterSearch($q);
$this -> assign('q', $q);
if ($q) {
$q = explode(' ', $q);
$or = array();
foreach($q as $word) {
if ($word) {
$or[] = "title LIKE '%$word%'";
$or[] = "keywords LIKE '%$word%'";
}
}
empty($or) or $where[] = $or;
}
$this -> assign('data', $this -> obj -> getList($page, $pageSize, $where, 'updatetime DESC, id DESC'));
$this -> assign('pages', $this -> obj -> pages());
$this -> assign('catid', $catid);
$this -> assign('passed', $passed);
$this -> assign('recycle', $recycle);
$this -> assign('headline', $headline);
$this -> assign('elite', $elite);
$this -> assign('ontop', $ontop);
$this -> assign('jmpurl', '?' . del_query_string('catid|page|q'));
$this -> assign('orderurl', '?' . del_query_string('order|field'));
$this -> assign('order', strtoupper(R('order')) == 'DESC'?'ASC':'DESC');
$this -> display('article');
}
// 审核通过
public function check() {
if ($this -> obj -> setFields(array('checker' => get_cookie('username'), 'checktime' => TIME, 'passed' => 1))) $this -> showMsg(L('OPERATE_SUCCESS'), $this -> referer);
else $this -> showMsg($this -> error);
}
}
?>
用两个不同的函数转换出的gbk文件,一个是去除了中文注释,一个是全部变成问号。