For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2005 > strtr & unicode









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author strtr & unicode
Nick Valeous

2005-02-20, 3:55 pm

I have a unicode string "ÜÝee" and I want to replace some letters with some
other letters:

When i use strtr, it messes up the string:

eg

$s = "ÜÝee";
echo $s; // will output ÜÝee
echo strtr($sTerm, "Ü", "|"); // will output |?|?ee


If you can't read the characters above, here is another example where 1234
are unicode characters (utf-8):

$s = "1234";
echo $s; // will output 1234
echo strtr($sTerm, "1", "|"); // will output |?|?34




any work arround? :-/



Nick Valeous

2005-02-20, 3:55 pm

I forgot to mention that my string contains both gr and french accented
characters. French are replaced normally, which gr become messed up. So
if you want to replicate the problem, you will have to add both gr
accented and french accented characters;



"Nick Valeous" <Mouhehe@hehe.com> wrote in message
news:cva8mn$2k2$1@usenet.otenet.gr...
> I have a unicode string "ÜÝee" and I want to replace some letters with

some
> other letters:
>
> When i use strtr, it messes up the string:
>
> eg
>
> $s = "ÜÝee";
> echo $s; // will output ÜÝee
> echo strtr($sTerm, "Ü", "|"); // will output |?|?ee
>
>
> If you can't read the characters above, here is another example where 1234
> are unicode characters (utf-8):
>
> $s = "1234";
> echo $s; // will output 1234
> echo strtr($sTerm, "1", "|"); // will output |?|?34
>
>
>
>
> any work arround? :-/
>
>
>



Oli Filth

2005-02-20, 3:55 pm

Nick Valeous wrote:
> I have a unicode string "ÜÝee" and I want to replace some letters with some
> other letters:
>
> When i use strtr, it messes up the string:
>
> eg
>
> $s = "ÜÝee";
> echo $s; // will output ÜÝee
> echo strtr($sTerm, "Ü", "|"); // will output |?|?ee
>
>
> If you can't read the characters above, here is another example where 1234
> are unicode characters (utf-8):
>
> $s = "1234";
> echo $s; // will output 1234
> echo strtr($sTerm, "1", "|"); // will output |?|?34
>
> any work arround? :-/


See http://uk.php.net/manual/en/ref.mbstring.php for multibyte string
functions.

--
Oli
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com