assign japanese string to var

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bhawin13@indiatimes.com

    assign japanese string to var

    Following code contains japanese string that is assigned to variable
    $str.
    code
    =============
    <?php
    $str = "$B%0%C%I%P%$% T%+%=(B";
    ?>
    =========
    When i am executing above program it gives me error as following.
    Parse error: parse error, unexpected $ in
    /var/www/html/bhavin/mohla1.2.2/b.php on line 3

    Do anybody have solution for the above problem.
    How can i assign above japanese string($B%0%C% I%P%$%T%+%=(B) to
    variable without error.


    Thank You
    bhawin13

  • Philip Ronan

    #2
    Re: assign japanese string to var

    bhawin13@indiat imes.com wrote:
    [color=blue]
    > Following code contains japanese string that is assigned to variable
    > $str.
    > code
    > =============
    > <?php
    > $str = "$B%0%C%I%P%$% T%+%=(J";
    > ?>
    > =========
    > When i am executing above program it gives me error as following.
    > Parse error: parse error, unexpected $ in
    > /var/www/html/bhavin/mohla1.2.2/b.php on line 3
    >
    > Do anybody have solution for the above problem.
    > How can i assign above japanese string($B%0%C% I%P%$%T%+%=(J) to
    > variable without error.[/color]

    You're using Shift-JIS encoding, aren't you?

    Don't. Use EUC-JP instead.

    You're getting problems because the last character ("$B%=(J") encodes as
    [&?131;] + [backslash] in shift-JIS encoding. PHP sees the backslash and
    escapes your closing quite mark, so the rest of your PHP script is getting
    swallowed up by the string. There are lots of other Shift-JIS characters
    that cause the same problem.

    In EUC-JP encoding, Japanese characters are all encoded with byte codes in
    the range 161-255 (or thereabouts), so this problem never happens.

    --
    phil [dot] ronan @ virgin [dot] net



    Comment

    • bhawin13

      #3
      Re: assign japanese string to var

      Yes you are right.
      I am using Shift-JIS charset.

      Is there any solution for above problem with Shift-JIS charset?

      Thank You
      bhawin13

      Comment

      • Philip Ronan

        #4
        Re: assign japanese string to var

        bhawin13 wrote:
        [color=blue]
        > Yes you are right.
        > I am using Shift-JIS charset.
        >
        > Is there any solution for above problem with Shift-JIS charset?[/color]


        I suppose you could add an extra backslash at the end of the string:

        $str = "$B%0%C%I%P%$% T%+%=(J\";

        It's messy, but it should work.

        --
        phil [dot] ronan @ virgin [dot] net



        Comment

        Working...