Try this (for utf-8 only) :
This supposes the string is well encoded.
Based on :
http://en.wikipedia.org/wiki/UTF-8
PHP Code:
RevertString( string[], output[], maxlen )
{
new len = strlen(string);
if( len > maxlen )
{
return 0;
}
maxlen = len;
new i;
for(--len; len>=0; len--)
{
output[i] = string[len];
}
new c;
for(i=0; i<maxlen; i++)
{
c = output[i];
if( c & 0xC0 == 0xC0 )
{
if( c & 0xF0 == 0xF0 )
{
output[i] = output[i-3];
output[i-3] = c;
c = output[i-2];
output[i-2] = output[i-1];
output[i-1] = c;
}
else if( c & 0xE0 == 0xE0 )
{
output[i] = output[i-2];
output[i-2] = c;
}
else
{
output[i] = output[i-1];
output[i-1] = c;
}
}
}
}
__________________