PHP常用函数记录【不定期整理】
2016-01-14 09:59
661 查看
1.复制目录
2.将非GBK字符集的编码转为GBK
3.将非UTF-8字符集的编码转为UTF-8
function copydir($strSrcDir, $strDstDir) { $dir = opendir($strSrcDir); if (!$dir) { return false; } if (!is_dir($strDstDir)) { if (!mkdir($strDstDir)) { return false; } } while (false !== ($file = readdir($dir))) { if (($file!='.') && ($file!='..')) { if (is_dir($strSrcDir.'/'.$file) ) { if (!copydir($strSrcDir.'/'.$file, $strDstDir.'/'.$file)) { return false; } } else { if (!copy($strSrcDir.'/'.$file, $strDstDir.'/'.$file)) { return false; } } } } closedir($dir); return true; }
2.将非GBK字符集的编码转为GBK
/** * 将非GBK字符集的编码转为GBK * * @param mixed $mixed 源数据 * * @return mixed GBK格式数据 */ function charsetToGBK($mixed) { if (is_array($mixed)) { foreach ($mixed as $k => $v) { if (is_array($v)) { $mixed[$k] = charsetToGBK($v); } else { $encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5')); if ($encode == 'UTF-8') { $mixed[$k] = iconv('UTF-8', 'GBK', $v); } } } } else { $encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5')); if ($encode == 'UTF-8') { $mixed = iconv('UTF-8', 'GBK', $mixed); } } return $mixed; }
3.将非UTF-8字符集的编码转为UTF-8
/** * 将非UTF-8字符集的编码转为UTF-8 * * @param mixed $mixed 源数据 * * @return mixed utf-8格式数据 */ function charsetToUTF8($mixed) { if (is_array($mixed)) { foreach ($mixed as $k => $v) { if (is_array($v)) { $mixed[$k] = charsetToUTF8($v); } else { $encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5')); if ($encode == 'EUC-CN') { $mixed[$k] = iconv('GBK', 'UTF-8', $v); } } } } else { $encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5')); if ($encode == 'EUC-CN') { $mixed = iconv('GBK', 'UTF-8', $mixed); } } return $mixed; }
相关文章推荐
- php读取csv的问题
- 使用PhpMysql实现图片文件上传下载
- php使用滑块验证码(极验验证)
- FTP文件传输协议两种模式 ftp协议集,错误码集,ftp客户端命令集
- php Debugging with Xdebug and Sublime Text 3(转)
- php 将解json的stdClass转为数组形式
- php服务器环境变量
- 四大组件之ContentProvider
- Composer安装出错——Unable to connect to getcomposer.org
- 简单php文件编写语法
- PHPCMS内链设置,PHPCMS关联链接设置
- 使用tftp时出现 tftp:timeout
- php经典算法
- kuangbin_ShortPath O (LightOJ 1074)
- PHP实现图片不变型裁剪及图片按比例裁剪的方法
- PHP实现QQ登录实例代码
- YII2 日志模块 之 使用数据库记录错误信息
- PHP 获取时间
- webstorm/phpstorm的Tab换4个空格
- webstorm/phpstorm的Tab换4个空格