#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Counting Chinese Words


    Hi,

    I had written a function to calculate total words in a string. For example:

    祝你 Happy Birthday - considered as 4 words
    祝你生日快樂 - considered as 6 words
    Happy Birthday 帥哥 2013 - considered as 5 words
    Happy Birthday 09/09/13 - considered as 3 words

    The problem is that I'd tested it on localhost (using AppServ Windows 7) and it works perfectly. But when I upload it to the server, the chinese words are calculated wrongly, example:

    祝你 Happy Birthday - become as 3 words
    祝你生日快樂 - become as 1 word
    Happy Birthday 帥哥 2013 - become as 4 words

    Not sure what's wrong with it.

    Can someone help on this?

    Here's my code:

    PHP Code:
    function count_total_word($txt){
            
            
    $total count(preg_split('~[\p{Z}\p{P}]+~u'$txtnullPREG_SPLIT_NO_EMPTY)) + 1// Count Words
            
    $total -= count(preg_split('~[/]+~u'$txtnullPREG_SPLIT_NO_EMPTY)); // Ignore "/"
            
    return $total;
        } 
    Localhost PHP: 5.2.6
    Server PHP: 5.2.17

    Thanks
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Crossposted at phpfreaks.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo