`dir /w` in big5 or utf-8

Discussion in 'PHP' started by thisismyphp, Jul 23, 2009.

  1. #1
    Dear all
    My English is pretty limited
    so my question short

    "功" is a Chinese word, It has some error in big5
    but it good in utf-8
    so utf-8 is better than big5 for Chinese


    my php code
    <?php
    echo "功";
    $txt=`dir /w`;
    echo $txt;

    ?>

    I run it by utf-8 and showed this
    -----------------------------------------------------------------------------------
    功

    �Ϻа� C �����ϺЬO os
    �ϺаϧǸ�: C414-1342

    C:\AppServ\www ���ؿ�

    [.] [..] [appserv] [cgi-bin]
    counter.txt demo0401.php demo0403.php index.php
    index_.php index_backup.php [nbproject] phpinfo.php
    [phpMyAdmin]
    7 ���ɮ� 6,044 �줸��
    6 �ӥؿ� 101,574,496,256 �줸�եi��
    -------------------------------------------------------------------------------------

    I think that is system error

    How can I fix it ?
     
    thisismyphp, Jul 23, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    UTF-8 is an 8bit encoding in Unicode, which for the most part can accept most languages and character sets just fine.

    The problem however, is that in PHP not all functions are unicode compatible, as a result using them may break the 8bit characters. So if your original source was unicode, and the database is unicode (utf8-bin), and it still ends up that way, then somewhere along the way it got broken.

    If that php code you have is the only thing the php file has, then you may actually have an issue with the browser's default. Try this as your PHP code instead:

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            </head>
            <body>
    <?php 
    echo "功";
    $txt=`dir /w`;
    echo $txt; 
    
    ?> 
    </body>
    </html>
    
    PHP:
    The main thing to take note of is the charset declaration in the meta tag (the same thing can be sent back to the browser via header(); like so.

    
    <?php
    header("Content-Type: text/html; charset=UTF-8");
    echo "功";
    $txt=`dir /w`;
    echo $txt; 
    
    ?>
    
    PHP:
     
    kblessinggr, Jul 23, 2009 IP
  3. thisismyphp

    thisismyphp Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I tried the code
    but it still error
    I think `dir /w` output the big5
    my browser and php page run by utf8

    how can `dir /w` output utf8?:(
     
    thisismyphp, Jul 23, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    that depends on your computer's native language. If your system is setup for Big5, then the output from dir /w is going to be in big5.

    If you have Multi-byte support installed on your server, you could do this.

    
    <?php
    header("Content-Type: text/html; charset=UTF-8");
    echo "功";
    $txt=`dir /w`;
    $txt= mb_convert_encoding($txt,"UTF-8","BIG-5");
    echo $txt; 
    ?>
    
    PHP:
    Essentially the function mb_conver_encoding, will take a string and convert it from one encoding to another. But it requires the multi-byte library to be installed for PHP (mbstring I think it's called).
     
    kblessinggr, Jul 24, 2009 IP