Raised This Month: $ Target: $400
 0% 

Reverse string stock (Unicode safe)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-26-2013 , 04:31   Re: Reverse string stock (Unicode safe)
Reply With Quote #4

Try this (for utf-8 only) :
This supposes the string is well encoded.

Based on : http://en.wikipedia.org/wiki/UTF-8

PHP Code:
RevertStringstring[], output[], maxlen )
{
    new 
len strlen(string);
    if( 
len maxlen )
    {
        return 
0;
    }

    
maxlen len;
    new 
i;
    for(--
lenlen>=0len--)
    {
        
output[i] = string[len];
    }

    new 
c;
    for(
i=0i<maxleni++)
    {
        
output[i];
        if( 
0xC0 == 0xC0 )
        {
            if( 
0xF0 == 0xF0 )
            {
                
output[i] = output[i-3];
                
output[i-3] = c;
                
output[i-2];
                
output[i-2] = output[i-1];
                
output[i-1] = c;
            }
            else if( 
0xE0 == 0xE0 )
            {
                
output[i] = output[i-2];
                
output[i-2] = c;
            }
            else
            {
                
output[i] = output[i-1];
                
output[i-1] = c;
            }
        }
    }

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 10-26-2013 at 04:33.
ConnorMcLeod is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode