<?php
/**
 * String Flipper Class
 * This class is a rewrite from here:
 * http://masnun.com/flipper/
 * I cleaned and simplyfied the code
 * Julius Beckmann
 * http://juliusbeckmann.de/blog/
 */

/**
 * String Flipper Class
 * This class can "flip" a text around 180°
 * by the use of unicode chars.
 */
class StringFlipper {

    
/**
     * Flips a string
     * @param string $str String to flip
     * @return string flipped string
     */
    
function flipString($str) {
        
$ret '';
        
$str strtolower($str);
        for (
$i strlen($str)-1$i >= 0; --$i
            
$ret .= $this->flipChar($str[$i]);
        return 
$ret;
    }

    
/**
     * Flips a single char
     * @param string $char Char to flip
     * @return string flipped Char
     */
    
function flipChar($char) {
        
$ret $char;
        
$charu $this->getUnicode($char);
        if(
$charu !== false) {
            if(
strlen($charu) > 2)
                
$charu '&#'.hexdec(substr($charu2)).';'
            
$ret $charu;
        }            
        return 
$ret;
    }

    
/**
     * Returns Unicode alternative
     * @param string $c char to convert
     * @return string alternate unicode char or false
     */
    
function getUnicode($c) {        
        
$ret false;
        switch(
$c) {
            
            
// Alphabet
            
case 'a'$ret '\u0250'; break;
            case 
'b'$ret 'q';      break;
            case 
'c'$ret '\u0254'; break;
            case 
'd'$ret 'p';      break;
            case 
'e'$ret '\u01DD'; break;
            case 
'f'$ret '\u025F'; break;
            case 
'g'$ret 'b';      break;
            case 
'h'$ret '\u0265'; break;
            case 
'i'$ret '\u0131'; break; //'\u0131\u0323' 
            
case 'j'$ret '\u0638'; break;
            case 
'k'$ret '\u029E'; break;
            case 
'l'$ret '1';      break;
            case 
'm'$ret '\u026F'; break;
            case 
'n'$ret 'u';      break;
            case 
'o'$ret 'o';      break;
            case 
'p'$ret 'd';      break;
            case 
'q'$ret 'b'; break;
            case 
'r'$ret '\u0279'; break;
            case 
's'$ret 's';      break;
            case 
't'$ret '\u0287'; break;
            case 
'u'$ret 'n';      break;
            case 
'v'$ret '\u028C'; break;
            case 
'w'$ret '\u028D'; break;
            case 
'x'$ret 'x';      break;
            case 
'y'$ret '\u028E'; break;
            case 
'z'$ret 'z';      break;
            
            
// Brackets
            
case '['$ret ']';      break;
            case 
']'$ret '[';      break;
            case 
'('$ret ')';      break;
            case 
')'$ret '(';      break;
            case 
'{'$ret '}';      break;
            case 
'}'$ret '{';      break;
            
            
// Dotting
            
case '?'$ret '\u00BF'; break;
            case 
'\u00BF'$ret '?'; break;
            case 
'!'$ret '\u00A1'; break;
            case 
'\u00A1'$ret '!'; break;        
            case 
'\''$ret ',';     break;
            case 
','$ret '\'';     break;
            
        }
        return 
$ret;
    }
}


?>