简体   繁体   English

PHP UTF-8编码

[英]Php UTF-8 encode

My Index 我的索引

defined("DS") ||  define("DS", DIRECTORY_SEPARATOR);
defined("ROOT_PATH") || define("ROOT_PATH", realpath(dirname(__FILE__)));
require_once(ROOT_PATH.DS.'classes'.DS.'Helper.php');

$page = 'default';

$uri = $_SERVER['REQUEST_URI'];

if(!empty($uri)){
    $first = substr($uri, 0, 1);
    if($first == '/') {
        $uri = substr($uri, 1);
    }
    if(!empty($uri)) {
        $uri = explode('?', $uri);
        $uri = explode('/', $uri[0]);
        $page = array_shift($uri);
    }
}

$content = array(
    'con' => Helper::getContent($page)
);

if(!empty($_GET['ajax'])) {
    echo json_encode($content);
} else {
    require_once('temp/temp.php');
}

My Classes 我的课程

class Helper {

    public static function getContent($file = null) {
        $file = 'content/'.$file.'.php';
        if(is_file($file)) {
            ob_start();
            require_once($file);
            return ob_get_clean();
        }
    }
}

When i show content page mixed characters involved.How can i do utf-8 ? 当我显示内容页面涉及的混合字符时,如何做utf-8?

You can find a documentation with a PHP script to re-encode your string here . 您可以在此处找到带有PHP脚本的文档,以对字符串进行重新编码。 The content is a french blog post but the script is a simple Gist in the middle page 内容是法语博客文章,但脚本是中间页中的简单要点

Maybe : 也许 :

header('Content-Type: text/html; charset=utf-8');

seen on topic Set HTTP header to UTF-8 using PHP 在主题上看到使用PHP将HTTP标头设置为UTF-8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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