php文件中有一变量$str,此变量中含有 unicode的字符,现echo $str 会含有 ? 这种符号
现要正常输出,应该怎么办,在线等
thanks

解决方案 »

  1.   

    保存为UTF-8格式,输出时加:
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      

  2.   


    //php文件头部,加上
    //文件保存为utf-8无bom格式
    header('Content-type: text/html; charset=utf-8');
      

  3.   

    显然 变量$str 中的内容是从外部得到的,否则你也不可能在一个文件中输入两种编码的文字!!!
    所谓 unicode 编码,通常是指 ucs-2 编码(当然还有其他,视来源而定)
    你可以通过 iconv 函数转换成你需要的编码
      

  4.   

    [code=PHP]
    iconv("gbk","utf-8",$str);
    [/Quote]
      

  5.   


    <?php
    echo iconv("ISO-8859-1", "UTF-8", "This is a test.");
    ?> iconv
    (PHP 4 >= 4.0.5, PHP 5)iconv -- Convert string to requested character encoding
    说明
    string iconv ( string in_charset, string out_charset, string str )
    Performs a character set conversion on the string str from in_charset to out_charset. 参数
    in_charset
    The input charset. out_charset
    The output charset. If you append the string //TRANSLIT to out_charset transliteration is activated. This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character. str
    The string to be converted. 
    返回值
    Returns the converted string or FALSE on failure.