Initial commit
This commit is contained in:
parent
83cf1bc068
commit
1d7bea2b91
3 changed files with 202 additions and 1 deletions
24
README.md
24
README.md
|
@ -1,2 +1,24 @@
|
||||||
# php-flip
|
# php-flip
|
||||||
PHP port of flip.js
|
|
||||||
|
PHP port of [flip.js][flipjs]
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
To install via `composer`, add the following to your `composer.json`:
|
||||||
|
|
||||||
|
```
|
||||||
|
"require": {
|
||||||
|
"joshtronic/php-flip": "dev-master"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run `composer update`
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```php
|
||||||
|
$flip = new joshtronic\Flip;
|
||||||
|
echo $flip->flip('text to flip');
|
||||||
|
```
|
||||||
|
|
||||||
|
[flipjs]: https://github.com/jergason/flipjs/blob/master/flip.js
|
||||||
|
|
21
composer.json
Normal file
21
composer.json
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"name": "joshtronic/php-flip",
|
||||||
|
"description": "PHP port of flip.js",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"keywords": ["string", "flip", "text"],
|
||||||
|
"homepage": "https://github.com/joshtronic/php-flip",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Josh Sherman",
|
||||||
|
"email": "josh@gravityblvd.com",
|
||||||
|
"homepage": "http://joshtronic"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {"joshtronic\\": "src/"}
|
||||||
|
}
|
||||||
|
}
|
158
src/flip.php
Normal file
158
src/flip.php
Normal file
|
@ -0,0 +1,158 @@
|
||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue