in reply to Re: substr + utf
in thread substr + utf

Made several tests before posting - at least on my PC it works with utf8 symbols as if it is 2 chars.
Maybe it depends on some OS settings?

Replies are listed 'Best First'.
Re^3: substr + utf
by ikegami (Patriarch) on Aug 18, 2005 at 16:28 UTC

    Are you sure the string is actually unicode? I think you interpreted every byte of your input as a character instead of interpreting your input as a unicode string. I'm not sure how to convert from one to the other.

    Maybe it depends on some OS settings?

    I doubt it. Try the following code.

    # $str = Approximation of "Eric" in Katakana. $str = "\x{30A8}\x{30FC}\x{30EA}\x{30AF}"; print(length($str), "\n"); # 4 $ch = substr($str, 0, 1); print(($ch eq "\x{30A8}" ? "equal" : "not equal"), "\n"); # equal