158 lines
3.4 KiB
PHP
158 lines
3.4 KiB
PHP
<?php
|
||
namespace joshtronic;
|
||
|
||
class Flip
|
||
{
|
||
// Taken from http://www.fileformat.info/convert/text/upside-down-map.htm
|
||
private $map = array(
|
||
'!' => '¡',
|
||
'"' => '„',
|
||
'&' => '⅋',
|
||
"'" => ',',
|
||
'(' => ')',
|
||
'.' => '˙',
|
||
'3' => 'Ɛ',
|
||
'4' => 'ᔭ',
|
||
'6' => '9',
|
||
'7' => 'Ɫ',
|
||
';' => '؛',
|
||
'<' => '>',
|
||
'?' => '¿',
|
||
'A' => '∀',
|
||
'B' => '𐐒',
|
||
'C' => 'Ↄ',
|
||
'D' => '◖',
|
||
'E' => 'Ǝ',
|
||
'F' => 'Ⅎ',
|
||
'G' => '⅁',
|
||
'J' => 'ſ',
|
||
'K' => '⋊',
|
||
'L' => '⅂',
|
||
'M' => 'W',
|
||
'N' => 'ᴎ',
|
||
'P' => 'Ԁ',
|
||
'Q' => 'Ό',
|
||
'R' => 'ᴚ',
|
||
'T' => '⊥',
|
||
'U' => '∩',
|
||
'V' => 'ᴧ',
|
||
'Y' => '⅄',
|
||
'[' => ']',
|
||
'_' => '‾',
|
||
'a' => 'ɐ',
|
||
'b' => 'q',
|
||
'c' => 'ɔ',
|
||
'd' => 'p',
|
||
'e' => 'ǝ',
|
||
'f' => 'ɟ',
|
||
'g' => 'ƃ',
|
||
'h' => 'ɥ',
|
||
'i' => 'ı',
|
||
'j' => 'ɾ',
|
||
'k' => 'ʞ',
|
||
'l' => 'ʃ',
|
||
'm' => 'ɯ',
|
||
'n' => 'u',
|
||
'r' => 'ɹ',
|
||
't' => 'ʇ',
|
||
'v' => 'ʌ',
|
||
'w' => 'ʍ',
|
||
'y' => 'ʎ',
|
||
'{' => '}',
|
||
'‿' => '⁀',
|
||
'⁅' => '⁆',
|
||
'∴' => '∵',
|
||
'¡' => '!',
|
||
'„' => '"',
|
||
'⅋' => '&',
|
||
',' => '\'',
|
||
')' => '(',
|
||
'˙' => '.',
|
||
'Ɛ' => '3',
|
||
'ᔭ' => '4',
|
||
'9' => '6',
|
||
'Ɫ' => '7',
|
||
'؛' => ';',
|
||
'>' => '<',
|
||
'¿' => '?',
|
||
'∀' => 'A',
|
||
'𐐒' => 'B',
|
||
'Ↄ' => 'C',
|
||
'◖' => 'D',
|
||
'Ǝ' => 'E',
|
||
'Ⅎ' => 'F',
|
||
'⅁' => 'G',
|
||
'ſ' => 'J',
|
||
'⋊' => 'K',
|
||
'⅂' => 'L',
|
||
'W' => 'M',
|
||
'ᴎ' => 'N',
|
||
'Ԁ' => 'P',
|
||
'Ό' => 'Q',
|
||
'ᴚ' => 'R',
|
||
'⊥' => 'T',
|
||
'∩' => 'U',
|
||
'ᴧ' => 'V',
|
||
'⅄' => 'Y',
|
||
']' => '[',
|
||
'‾' => '_',
|
||
'ɐ' => 'a',
|
||
'q' => 'b',
|
||
'ɔ' => 'c',
|
||
'p' => 'd',
|
||
'ǝ' => 'e',
|
||
'ɟ' => 'f',
|
||
'ƃ' => 'g',
|
||
'ɥ' => 'h',
|
||
'ı' => 'i',
|
||
'ɾ' => 'j',
|
||
'ʞ' => 'k',
|
||
'ʃ' => 'l',
|
||
'ɯ' => 'm',
|
||
'u' => 'n',
|
||
'ɹ' => 'r',
|
||
'ʇ' => 't',
|
||
'ʌ' => 'v',
|
||
'ʍ' => 'w',
|
||
'ʎ' => 'y',
|
||
'}' => '{',
|
||
'⁀' => '‿',
|
||
'⁆' => '⁅',
|
||
'∵' => '∴',
|
||
);
|
||
|
||
private $flipped_guy = array(
|
||
'/', '(', ' ', '.', ' ', '0', ' ', '.', '\\', '\\', ')'
|
||
);
|
||
|
||
public function __construct()
|
||
{
|
||
// Maps inverted characters
|
||
foreach ($this->map as $a => $b) {
|
||
$this->map[$b] = $a;
|
||
}
|
||
}
|
||
|
||
public function flip($string)
|
||
{
|
||
if (!is_string($string)) {
|
||
return null;
|
||
}
|
||
|
||
$length = strlen($string) - 1;
|
||
$results = array();
|
||
|
||
for ($i = $length; $i >= 0; $i--) {
|
||
if ($i >= 6 && substr($string, $i - 7, $i) == '(╯°□°)╯') {
|
||
$results = array_merge($results, $this->flipped_guy);
|
||
$i -= 7;
|
||
} else {
|
||
$chr = $string[$i];
|
||
$results[] = isset($this->map[$chr]) ? $this->map[$chr] : $chr;
|
||
}
|
||
}
|
||
|
||
return implode('', $results);
|
||
}
|
||
}
|
||
|