├── .gitignore
├── .travis.yml
├── phpunit.xml
├── composer.json
├── test
├── unit
│ ├── sample.json
│ └── RabbitUnitTest.php
└── Rabbit.php
├── LICENSE
├── README.md
└── src
└── Rabbit.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.lock
3 | /build
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.3
5 | - 5.4
6 | - 5.5
7 | - 5.6
8 | - hhvm
9 |
10 | before_script:
11 | - composer self-update
12 | - composer install --prefer-source --no-interaction --dev
13 |
14 | script: phpunit
15 |
16 | notifications:
17 | - email: true
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ./test/unit/
5 |
6 |
7 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rabbit-converter/rabbit-php",
3 | "description": "Another Zawgyi <=> Unicode Converter",
4 | "license": "MIT",
5 | "keywords": [
6 | "converter",
7 | "zawgyi",
8 | "unicode",
9 | "myanmar-font"
10 | ],
11 | "homepage": "http://saturngod.github.io/Rabbit",
12 | "authors": [
13 | {
14 | "name": "Saturngod",
15 | "email": "me@saturngod.net"
16 | },
17 | {
18 | "name": "Nyan Lynn Htut",
19 | "email": "nyanlynnhtut@hexcores.com"
20 | }
21 | ],
22 | "require": {
23 | "php": ">=5.3.0"
24 | },
25 | "require-dev": {
26 | "phpunit/phpunit": "~4.0"
27 | },
28 | "autoload": {
29 | "files": [
30 | "src/Rabbit.php"
31 | ]
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test/unit/sample.json:
--------------------------------------------------------------------------------
1 | {
2 | "zg" : [
3 | "မဂၤလာပါ",
4 | "သီဟိုဠ္မွ ဉာဏ္ႀကီးရွင္သည္ အာယုဝဍ္ဎနေဆးၫႊန္းစာကို ဇလြန္ေဈးေဘးဗာဒံပင္ထက္ အဓိ႒ာန္လ်က္ ဂဃနဏဖတ္ခဲ့သည္။",
5 | "ေယဓမၼာ ေဟတုပၸဘဝါ ေတသံ ေဟတုံ တထာဂေတာ အာဟ ေတသၪၥ ေယာနိေရာေဓါ ဧဝံ ဝါဒီ မဟာသမေဏာ။",
6 | "ျမန္မာလိုေျပာမယ္လကြာ",
7 | "ေဘာလုံးကန္တာမွ ေကာင္းဦးမယ္",
8 | "Rabbit ကြန္ဗက္တာကို သိလား",
9 | "တေစၦ တစ္ေကာင္မိထားတယ္",
10 | "တိရစာၦန္ တစ္ေကာင္ ကမာၻေျမႀကီးမွာ ကမာၻ႔ေျမအဆီအလႊာမ်ား စားသုံး"
11 | ],
12 |
13 | "uni" : [
14 | "မင်္ဂလာပါ",
15 | "သီဟိုဠ်မှ ဉာဏ်ကြီးရှင်သည် အာယုဝဍ်ဎနဆေးညွှန်းစာကို ဇလွန်ဈေးဘေးဗာဒံပင်ထက် အဓိဋ္ဌာန်လျက် ဂဃနဏဖတ်ခဲ့သည်။",
16 | "ယေဓမ္မာ ဟေတုပ္ပဘဝါ တေသံ ဟေတုံ တထာဂတော အာဟ တေသဉ္စ ယောနိရောဓေါ ဧဝံ ဝါဒီ မဟာသမဏော။",
17 | "မြန်မာလိုပြောမယ်လကွာ",
18 | "ဘောလုံးကန်တာမှ ကောင်းဦးမယ်",
19 | "Rabbit ကွန်ဗက်တာကို သိလား",
20 | "တစ္ဆေ တစ်ကောင်မိထားတယ်",
21 | "တိရစ္ဆာန် တစ်ကောင် ကမ္ဘာမြေကြီးမှာ ကမ္ဘာ့မြေအဆီအလွှာများ စားသုံး"
22 | ]
23 | }
--------------------------------------------------------------------------------
/test/unit/RabbitUnitTest.php:
--------------------------------------------------------------------------------
1 | sampleStrings = json_decode(file_get_contents(__DIR__.'/sample.json'), true);
11 | }
12 |
13 | public function tearDown()
14 | {
15 | $this->sampleStrings = array();
16 | }
17 |
18 | /**
19 | * Test Zawgyi to Unicode converting.
20 | */
21 | public function testZg2uniConverting()
22 | {
23 | foreach ($this->sampleStrings['zg'] as $index => $zawgyi) {
24 | $unicode = $this->sampleStrings['uni'][$index];
25 |
26 | $this->assertSame($unicode, Rabbit::zg2uni($zawgyi));
27 | }
28 | }
29 |
30 | /**
31 | * Test Unicode to Zawgyi converting.
32 | */
33 | public function testUni2zgConverting()
34 | {
35 | foreach ($this->sampleStrings['uni'] as $index => $unicode) {
36 | $zawgyi = $this->sampleStrings['zg'][$index];
37 |
38 | $this->assertSame($zawgyi, Rabbit::uni2zg($unicode));
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Htain Lin Shwe/Rabbit-Converter
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Rabbit-PHP
2 |
3 | 
4 |
5 | [](https://travis-ci.org/Rabbit-Converter/Rabbit-PHP)
6 |
7 | **Another Zawgyi <=> Unicode Converter for composer packagist**
8 |
9 | ## About
10 |
11 | Zawgyi to Unicode has been written in [2011](https://github.com/saturngod/ZG2Uni_JS/commits/master). Now, unicode to zawgyi has been finished.
12 |
13 | ## Motivation. Why another converter ?
14 |
15 | When I was writting [ZG2uni](https://github.com/saturngod/ZG2Uni_JS/), [Parabaik](https://github.com/ngwestar/parabaik) was not opensource. At that time, I need to use for [MYSTERY ZILLION](http://www.mysteryzillion.org) for converting the whole database to Unicode.
16 |
17 | For Unicode to Zawgyi, Parabaik is under the ~~GPL license and cannot use in iOS app and Android App~~ LGPL. So, I decided to write new one with **WTFPL license**. This library is under MIT License.
18 |
19 | > I cannot promise , it's correct 100% after converting.
20 |
21 | > If you are not using in app or program and just for converting the text , please use [Parabaik](https://github.com/ngwestar/parabaik)
22 |
23 | ## Installation
24 |
25 | Install using composer:
26 |
27 | ```json
28 | composer require "rabbit-converter/rabbit-php:dev-master"
29 | ```
30 |
31 | ## Usage
32 |
33 | ```php
34 |
35 | Rabbit::zg2uni("သီဟိုဠ္မွ ဉာဏ္ႀကီးရွင္သည္ အာယုဝဍ္ဎနေဆးၫႊန္းစာကို ဇလြန္ေဈးေဘးဗာဒံပင္ထက္ အဓိ႒ာန္လ်က္ ဂဃနဏဖတ္ခဲ့သည္။");
36 |
37 | Rabbit::uni2zg("သီဟိုဠ်မှ ဉာဏ်ကြီးရှင်သည် အာယုဝဍ်ဎနဆေးညွှန်းစာကို ဇလွန်ဈေးဘေးဗာဒံပင်ထက် အဓိဋ္ဌာန်လျက် ဂဃနဏဖတ်ခဲ့သည်။");
38 |
39 | ```
40 |
41 | ## Contributing
42 |
43 | 1. Fork it ( https://github.com/Rabbit-Converter/Rabbit-PHP )
44 | 2. Create your feature branch (`git checkout -b my-new-feature`)
45 | 3. Commit your changes (`git commit -am 'Add some feature'`)
46 | 4. Push to the branch (`git push origin my-new-feature`)
47 | 5. Create a new Pull Request
48 |
49 | ## License
50 |
51 | MIT
52 |
--------------------------------------------------------------------------------
/test/Rabbit.php:
--------------------------------------------------------------------------------
1 | Unicode Converter.
5 | *
6 | * @author Saturngod
7 | */
8 | class Rabbit
9 | {
10 | /**
11 | * Convert unicode string to zawgyi.
12 | *
13 | * @param string $unicode
14 | * @return string
15 | */
16 | public static function uni2zg($unicode)
17 | {
18 | $rule = json_decode("[{\"from\":\"\u1004\u103a\u1039\",\"to\":\"\u1064\"},{\"from\":\"\u1039\u1010\u103d\",\"to\":\"\u1096\"},{\"from\":\"\u1014(?=[\u1030\u103d\u103e\u102f\u1039])\",\"to\":\"\u108f\"},{\"from\":\"\u102b\u103a\",\"to\":\"\u105a\"},{\"from\":\"\u100b\u1039\u100c\",\"to\":\"\u1092\"},{\"from\":\"\u102d\u1036\",\"to\":\"\u108e\"},{\"from\":\"\u104e\u1004\u103a\u1038\",\"to\":\"\u104e\"},{\"from\":\"[\u1025\u1009](?=[\u1039\u102f\u1030])\",\"to\":\"\u106a\"},{\"from\":\"[\u1025\u1009](?=[\u103a])\",\"to\":\"\u1025\"},{\"from\":\"\u100a(?=[\u1039\u102f\u1030\u103d])\",\"to\":\"\u106b\"},{\"from\":\"(\u1039[\u1000-\u1021])\u102f\",\"to\":\"$1\u1033\"},{\"from\":\"(\u1039[\u1000-\u1021])\u1030\",\"to\":\"$1\u1034\"},{\"from\":\"\u1039\u1000\",\"to\":\"\u1060\"},{\"from\":\"\u1039\u1001\",\"to\":\"\u1061\"},{\"from\":\"\u1039\u1002\",\"to\":\"\u1062\"},{\"from\":\"\u1039\u1003\",\"to\":\"\u1063\"},{\"from\":\"\u1039\u1005\",\"to\":\"\u1065\"},{\"from\":\"\u1039\u1007\",\"to\":\"\u1068\"},{\"from\":\"\u1039\u1008\",\"to\":\"\u1069\"},{\"from\":\"\u100a(?=[\u1039\u102f\u1030])\",\"to\":\"\u106b\"},{\"from\":\"\u1039\u100b\",\"to\":\"\u106c\"},{\"from\":\"\u1039\u100c\",\"to\":\"\u106d\"},{\"from\":\"\u100d\u1039\u100d\",\"to\":\"\u106e\"},{\"from\":\"\u100e\u1039\u100d\",\"to\":\"\u106f\"},{\"from\":\"\u1039\u100f\",\"to\":\"\u1070\"},{\"from\":\"\u1039\u1010\",\"to\":\"\u1071\"},{\"from\":\"\u1039\u1011\",\"to\":\"\u1073\"},{\"from\":\"\u1039\u1012\",\"to\":\"\u1075\"},{\"from\":\"\u1039\u1013\",\"to\":\"\u1076\"},{\"from\":\"\u1039\u1013\",\"to\":\"\u1076\"},{\"from\":\"\u1039\u1014\",\"to\":\"\u1077\"},{\"from\":\"\u1039\u1015\",\"to\":\"\u1078\"},{\"from\":\"\u1039\u1016\",\"to\":\"\u1079\"},{\"from\":\"\u1039\u1017\",\"to\":\"\u107a\"},{\"from\":\"\u1039\u1018\",\"to\":\"\u107b\"},{\"from\":\"\u1039\u1019\",\"to\":\"\u107c\"},{\"from\":\"\u1039\u101c\",\"to\":\"\u1085\"},{\"from\":\"\u103f\",\"to\":\"\u1086\"},{\"from\":\"(\u103c)\u103e\",\"to\":\"$1\u1087\"},{\"from\":\"\u103d\u103e\",\"to\":\"\u108a\"},{\"from\":\"(\u1064)([\u1031]?)([\u103c]?)([\u1000-\u1021])\u102d\",\"to\":\"$2$3$4\u108b\"},{\"from\":\"(\u1064)([\u1031]?)([\u103c]?)([\u1000-\u1021])\u102e\",\"to\":\"$2$3$4\u108c\"},{\"from\":\"(\u1064)([\u1031]?)([\u103c]?)([\u1000-\u1021])\u1036\",\"to\":\"$2$3$4\u108d\"},{\"from\":\"(\u1064)([\u1031]?)([\u103c]?)([\u1000-\u1021])\",\"to\":\"$2$3$4$1\"},{\"from\":\"\u101b(?=[\u102f\u1030\u103d\u108a])\",\"to\":\"\u1090\"},{\"from\":\"\u100f\u1039\u100d\",\"to\":\"\u1091\"},{\"from\":\"\u100b\u1039\u100b\",\"to\":\"\u1097\"},{\"from\":\"([\u1000-\u1021\u108f\u1029\u1090])([\u1060-\u1069\u106c\u106d\u1070-\u107c\u1085\u108a])?([\u103b-\u103e]*)?\u1031\",\"to\":\"\u1031$1$2$3\"},{\"from\":\"([\u1000-\u1021\u1029])([\u1060-\u1069\u106c\u106d\u1070-\u107c\u1085])?(\u103c)\",\"to\":\"$3$1$2\"},{\"from\":\"\u103a\",\"to\":\"\u1039\"},{\"from\":\"\u103b\",\"to\":\"\u103a\"},{\"from\":\"\u103c\",\"to\":\"\u103b\"},{\"from\":\"\u103d\",\"to\":\"\u103c\"},{\"from\":\"\u103e\",\"to\":\"\u103d\"},{\"from\":\"\u103d\u102f\",\"to\":\"\u1088\"},{\"from\":\"([\u102f\u1030\u1014\u101b\u103c\u108a\u103d\u1088])([\u1032\u1036]{0,1})\u1037\",\"to\":\"$1$2\u1095\"},{\"from\":\"\u102f\u1095\",\"to\":\"\u102f\u1094\"},{\"from\":\"([\u1014\u101b])([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])\u1037\",\"to\":\"$1$2\u1095\"},{\"from\":\"\u1095\u1039\",\"to\":\"\u1094\u1039\"},{\"from\":\"([\u103a\u103b])([\u1000-\u1021])([\u1036\u102d\u102e\u108b\u108c\u108d\u108e]?)\u102f\",\"to\":\"$1$2$3\u1033\"},{\"from\":\"([\u103a\u103b])([\u1000-\u1021])([\u1036\u102d\u102e\u108b\u108c\u108d\u108e]?)\u1030\",\"to\":\"$1$2$3\u1034\"},{\"from\":\"\u103a\u102f\",\"to\":\"\u103a\u1033\"},{\"from\":\"\u103a([\u1036\u102d\u102e\u108b\u108c\u108d\u108e])\u102f\",\"to\":\"\u103a$1\u1033\"},{\"from\":\"([\u103a\u103b])([\u1000-\u1021])\u1030\",\"to\":\"$1$2\u1034\"},{\"from\":\"\u103a\u1030\",\"to\":\"\u103a\u1034\"},{\"from\":\"\u103a([\u1036\u102d\u102e\u108b\u108c\u108d\u108e])\u1030\",\"to\":\"\u103a$1\u1034\"},{\"from\":\"\u103d\u1030\",\"to\":\"\u1089\"},{\"from\":\"\u103b([\u1000\u1003\u1006\u100f\u1010\u1011\u1018\u101a\u101c\u101a\u101e\u101f])\",\"to\":\"\u107e$1\"},{\"from\":\"\u107e([\u1000\u1003\u1006\u100f\u1010\u1011\u1018\u101a\u101c\u101a\u101e\u101f])([\u103c\u108a])([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])\",\"to\":\"\u1084$1$2$3\"},{\"from\":\"\u107e([\u1000\u1003\u1006\u100f\u1010\u1011\u1018\u101a\u101c\u101a\u101e\u101f])([\u103c\u108a])\",\"to\":\"\u1082$1$2\"},{\"from\":\"\u107e([\u1000\u1003\u1006\u100f\u1010\u1011\u1018\u101a\u101c\u101a\u101e\u101f])([\u1033\u1034]?)([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])\",\"to\":\"\u1080$1$2$3\"},{\"from\":\"\u103b([\u1000-\u1021])([\u103c\u108a])([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])\",\"to\":\"\u1083$1$2$3\"},{\"from\":\"\u103b([\u1000-\u1021])([\u103c\u108a])\",\"to\":\"\u1081$1$2\"},{\"from\":\"\u103b([\u1000-\u1021])([\u1033\u1034]?)([\u1032\u1036\u102d\u102e\u108b\u108c\u108d\u108e])\",\"to\":\"\u107f$1$2$3\"},{\"from\":\"\u103a\u103d\",\"to\":\"\u103d\u103a\"},{\"from\":\"\u103a([\u103c\u108a])\",\"to\":\"$1\u107d\"},{\"from\":\"([\u1033\u1034])\u1094\",\"to\":\"$1\u1095\"}]", true);
19 |
20 | return self::replaceWithRule($rule, $unicode);
21 | }
22 |
23 | /**
24 | * Convert zawgyi string to unicode.
25 | *
26 | * @param string $unicode
27 | * @return string
28 | */
29 | public static function zg2uni($zawgyi)
30 | {
31 | $rule = json_decode("[{\"from\":\"(\u103d|\u1087)\",\"to\":\"\u103e\"},{\"from\":\"\u103c\",\"to\":\"\u103d\"},{\"from\":\"(\u103b|\u107e|\u107f|\u1080|\u1081|\u1082|\u1083|\u1084)\",\"to\":\"\u103c\"},{\"from\":\"(\u103a|\u107d)\",\"to\":\"\u103b\"},{\"from\":\"\u1039\",\"to\":\"\u103a\"},{\"from\":\"\u106a\",\"to\":\"\u1009\"},{\"from\":\"\u106b\",\"to\":\"\u100a\"},{\"from\":\"\u106c\",\"to\":\"\u1039\u100b\"},{\"from\":\"\u106d\",\"to\":\"\u1039\u100c\"},{\"from\":\"\u106e\",\"to\":\"\u100d\u1039\u100d\"},{\"from\":\"\u106f\",\"to\":\"\u100d\u1039\u100e\"},{\"from\":\"\u1070\",\"to\":\"\u1039\u100f\"},{\"from\":\"(\u1071|\u1072)\",\"to\":\"\u1039\u1010\"},{\"from\":\"\u1060\",\"to\":\"\u1039\u1000\"},{\"from\":\"\u1061\",\"to\":\"\u1039\u1001\"},{\"from\":\"\u1062\",\"to\":\"\u1039\u1002\"},{\"from\":\"\u1063\",\"to\":\"\u1039\u1003\"},{\"from\":\"\u1065\",\"to\":\"\u1039\u1005\"},{\"from\":\"\u1068\",\"to\":\"\u1039\u1007\"},{\"from\":\"\u1069\",\"to\":\"\u1039\u1008\"},{\"from\":\"/(\u1073|\u1074)/g\",\"to\":\"\u1039\u1011\"},{\"from\":\"\u1075\",\"to\":\"\u1039\u1012\"},{\"from\":\"\u1076\",\"to\":\"\u1039\u1013\"},{\"from\":\"\u1077\",\"to\":\"\u1039\u1014\"},{\"from\":\"\u1078\",\"to\":\"\u1039\u1015\"},{\"from\":\"\u1079\",\"to\":\"\u1039\u1016\"},{\"from\":\"\u107a\",\"to\":\"\u1039\u1017\"},{\"from\":\"\u107c\",\"to\":\"\u1039\u1019\"},{\"from\":\"\u1085\",\"to\":\"\u1039\u101c\"},{\"from\":\"\u1033\",\"to\":\"\u102f\"},{\"from\":\"\u1034\",\"to\":\"\u1030\"},{\"from\":\"\u103f\",\"to\":\"\u1030\"},{\"from\":\"\u1086\",\"to\":\"\u103f\"},{\"from\":\"\u1036\u1088\",\"to\":\"\u1088\u1036\"},{\"from\":\"\u1088\",\"to\":\"\u103e\u102f\"},{\"from\":\"\u1089\",\"to\":\"\u103e\u1030\"},{\"from\":\"\u108a\",\"to\":\"\u103d\u103e\"},{\"from\":\"([\u1000-\u1021])\u1064\",\"to\":\"\u1004\u103a\u1039$1\"},{\"from\":\"([\u1000-\u1021])\u108b\",\"to\":\"\u1004\u103a\u1039$1\u102d\"},{\"from\":\"([\u1000-\u1021])\u108c\",\"to\":\"\u1004\u103a\u1039$1\u102e\"},{\"from\":\"([\u1000-\u1021])\u108d\",\"to\":\"\u1004\u103a\u1039$1\u1036\"},{\"from\":\"\u108e\",\"to\":\"\u102d\u1036\"},{\"from\":\"\u108f\",\"to\":\"\u1014\"},{\"from\":\"\u1090\",\"to\":\"\u101b\"},{\"from\":\"\u1091\",\"to\":\"\u100f\u1039\u1091\"},{\"from\":\"\u1019\u102c(\u107b|\u1093)\",\"to\":\"\u1019\u1039\u1018\u102c\"},{\"from\":\"(\u107b|\u1093)\",\"to\":\"\u1039\u1018\"},{\"from\":\"(\u1094|\u1095)\",\"to\":\"\u1037\"},{\"from\":\"\u1096\",\"to\":\"\u1039\u1010\u103d\"},{\"from\":\"\u1097\",\"to\":\"\u100b\u1039\u100b\"},{\"from\":\"\u103c([\u1000-\u1021])([\u1000-\u1021])?\",\"to\":\"$1\u103c$2\"},{\"from\":\"([\u1000-\u1021])\u103c\u103a\",\"to\":\"\u103c$1\u103a\"},{\"from\":\"\u1031([\u1000-\u1021])(\u103e)?(\u103b)?\",\"to\":\"$1$2$3\u1031\"},{\"from\":\"([\u1000-\u1021])\u1031([\u103b\u103c\u103d\u103e]+)\",\"to\":\"$1$2\u1031\"},{\"from\":\"\u1032\u103d\",\"to\":\"\u103d\u1032\"},{\"from\":\"\u103d\u103b\",\"to\":\"\u103b\u103d\"},{\"from\":\"\u103a\u1037\",\"to\":\"\u1037\u103a\"},{\"from\":\"\u102f(\u102d|\u102e|\u1036|\u1037)\u102f\",\"to\":\"\u102f$1\"},{\"from\":\"\u102f\u102f\",\"to\":\"\u102f\"},{\"from\":\"(\u102f|\u1030)(\u102d|\u102e)\",\"to\":\"$2$1\"},{\"from\":\"(\u103e)(\u103b|\u1037)\",\"to\":\"$2$1\"},{\"from\":\"\u1025(\u103a|\u102c)\",\"to\":\"\u1009$1\"},{\"from\":\"\u1025\u102e\",\"to\":\"\u1026\"},{\"from\":\"\u1005\u103b\",\"to\":\"\u1008\"},{\"from\":\"\u1036(\u102f|\u1030)\",\"to\":\"$1\u1036\"},{\"from\":\"\u1031\u1037\u103e\",\"to\":\"\u103e\u1031\u1037\"},{\"from\":\"\u1031\u103e\u102c\",\"to\":\"\u103e\u1031\u102c\"},{\"from\":\"\u105a\",\"to\":\"\u102b\u103a\"},{\"from\":\"\u1031\u103b\u103e\",\"to\":\"\u103b\u103e\u1031\"},{\"from\":\"(\u102d|\u102e)(\u103d|\u103e)\",\"to\":\"$2$1\"},{\"from\":\"\u102c\u1039([\u1000-\u1021])\",\"to\":\"\u1039$1\u102c\"},{\"from\":\"\u103c\u1004\u103a\u1039([\u1000-\u1021])\",\"to\":\"\u1004\u103a\u1039$1\u103c\"},{\"from\":\"\u1039\u103c\u103a\u1039([\u1000-\u1021])\",\"to\":\"\u103a\u1039$1\u103c\"},{\"from\":\"\u103c\u1039([\u1000-\u1021])\",\"to\":\"\u1039$1\u103c\"},{\"from\":\"\u1036\u1039([\u1000-\u1021])\",\"to\":\"\u1039$1\u1036\"},{\"from\":\"\u1092\",\"to\":\"\u100b\u1039\u100c\"},{\"from\":\"\u104e\",\"to\":\"\u104e\u1004\u103a\u1038\"},{\"from\":\"\u1040(\u102b|\u102c|\u1036)\",\"to\":\"\u101d$1\"},{\"from\":\"\u1025\u1039\",\"to\":\"\u1009\u1039\"},{\"from\":\"([\u1000-\u1021])\u103c\u1031\u103d\",\"to\":\"$1\u103c\u103d\u1031\"},{\"from\":\"([\u1000-\u1021])\u103d\u1031\u103b\",\"to\":\"$1\u103b\u103d\u1031\"},{\"from\":\"([\u1000-\u1021])\u1031(\u1039[\u1000-\u1021])\",\"to\":\"$1$2\u1031\"}]", true);
32 |
33 | return self::replaceWithRule($rule, $zawgyi);
34 | }
35 |
36 | /**
37 | * Replace the string with rules.
38 | *
39 | * @param array $rule
40 | * @param string $output
41 | * @return string
42 | */
43 | protected static function replaceWithRule($rule, $output)
44 | {
45 | foreach ($rule as $data) {
46 | $from = "~".json_decode('"'.$data["from"].'"')."~u";
47 | $to = json_decode('"'.$data["to"].'"');
48 | $output = preg_replace($from, $to, $output);
49 | }
50 |
51 | return $output;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Rabbit.php:
--------------------------------------------------------------------------------
1 | Unicode Converter.
5 | *
6 | * @author Saturngod
7 | */
8 | class Rabbit
9 | {
10 | /**
11 | * Rabbit Converter version.
12 | *
13 | * @var string
14 | */
15 | const VERSION = '1.1.3
16 | ';
17 |
18 | /**
19 | * Convert unicode string to zawgyi.
20 | *
21 | * @param string $unicode
22 | * @return string
23 | */
24 | public static function uni2zg($unicode)
25 | {
26 | $rule = json_decode("[ { \"from\": \"\\u1004\\u103a\\u1039\", \"to\": \"\\u1064\" }, { \"from\": \"\\u1039\\u1010\\u103d\", \"to\": \"\\u1096\" }, { \"from\": \"\\u102b\\u103a\", \"to\": \"\\u105a\" }, { \"from\": \"\\u102d\\u1036\", \"to\": \"\\u108e\" }, { \"from\": \"\\u104e\\u1004\\u103a\\u1038\", \"to\": \"\\u104e\" }, { \"from\": \"[\\u1025\\u1009](?=\\u1039)\", \"to\": \"\\u106a\" }, { \"from\": \"\\u1009(?=[\\u102f\\u1030])\", \"to\": \"\\u1025\" }, { \"from\": \"[\\u1025\\u1009](?=[\\u1037]?[\\u103a])\", \"to\": \"\\u1025\" }, { \"from\": \"\\u100a(?=[\\u1039\\u103d])\", \"to\": \"\\u106b\" }, { \"from\": \"(\\u1039[\\u1000-\\u1021])(\\u102D){0,1}\\u102f\", \"to\": \"$1$2\\u1033\" }, { \"from\": \"(\\u1039[\\u1000-\\u1021])\\u1030\", \"to\": \"$1\\u1034\" }, { \"from\": \"\\u1014(?=[\\u102d\\u102e\\u102f\\u103A]?[\\u1030\\u103d\\u103e\\u102f\\u1039])\", \"to\": \"\\u108f\" }, { \"from\": \"\\u1014(?=\\u103A\\u102F )\", \"to\": \"\\u108f\" }, { \"from\" : \"\\u1014\\u103c\", \"to\" : \"\\u108f\\u103c\" }, { \"from\": \"\\u1039\\u1000\", \"to\": \"\\u1060\" }, { \"from\": \"\\u1039\\u1001\", \"to\": \"\\u1061\" }, { \"from\": \"\\u1039\\u1002\", \"to\": \"\\u1062\" }, { \"from\": \"\\u1039\\u1003\", \"to\": \"\\u1063\" }, { \"from\": \"\\u1039\\u1005\", \"to\": \"\\u1065\" }, { \"from\": \"\\u1039\\u1006\", \"to\": \"\\u1066\" }, { \"from\": \"\\u1039\\u1007\", \"to\": \"\\u1068\" }, { \"from\": \"\\u1039\\u1008\", \"to\": \"\\u1069\" }, { \"from\": \"\\u1039\\u100b\", \"to\": \"\\u106c\" }, { \"from\": \"\\u100b\\u1039\\u100c\", \"to\": \"\\u1092\" }, { \"from\": \"\\u1039\\u100c\", \"to\": \"\\u106d\" }, { \"from\": \"\\u100d\\u1039\\u100d\", \"to\": \"\\u106e\" }, { \"from\": \"\\u100d\\u1039\\u100e\", \"to\": \"\\u106f\" }, { \"from\": \"\\u1039\\u100f\", \"to\": \"\\u1070\" }, { \"from\": \"\\u1039\\u1010\", \"to\": \"\\u1071\" }, { \"from\": \"\\u1039\\u1011\", \"to\": \"\\u1073\" }, { \"from\": \"\\u1039\\u1012\", \"to\": \"\\u1075\" }, { \"from\": \"\\u1039\\u1013\", \"to\": \"\\u1076\" }, { \"from\": \"\\u1039[\\u1014\\u108f]\", \"to\": \"\\u1077\" }, { \"from\": \"\\u1039\\u1015\", \"to\": \"\\u1078\" }, { \"from\": \"\\u1039\\u1016\", \"to\": \"\\u1079\" }, { \"from\": \"\\u1039\\u1017\", \"to\": \"\\u107a\" }, { \"from\": \"\\u1039\\u1018\", \"to\": \"\\u107b\" }, { \"from\": \"\\u1039\\u1019\", \"to\": \"\\u107c\" }, { \"from\": \"\\u1039\\u101c\", \"to\": \"\\u1085\" }, { \"from\": \"\\u103f\", \"to\": \"\\u1086\" }, { \"from\": \"\\u103d\\u103e\", \"to\": \"\\u108a\" }, { \"from\": \"(\\u1064)([\\u1000-\\u1021])([\\u103b\\u103c]?)\\u102d\", \"to\": \"$2$3\\u108b\" }, { \"from\": \"(\\u1064)([\\u1000-\\u1021])([\\u103b\\u103c]?)\\u102e\", \"to\": \"$2$3\\u108c\" }, { \"from\": \"(\\u1064)([\\u1000-\\u1021])([\\u103b\\u103c]?)\\u1036\", \"to\": \"$2$3\\u108d\" }, { \"from\": \"(\\u1064)([\\u1000-\\u1021\\u1040-\\u1049])([\\u103b\\u103c]?)([\\u1031]?)\", \"to\": \"$2$3$4$1\" }, { \"from\": \"\\u101b(?=([\\u102d\\u102e]?)[\\u102f\\u1030\\u103d\\u108a])\", \"to\": \"\\u1090\" }, { \"from\": \"\\u100f\\u1039\\u100d\", \"to\": \"\\u1091\" }, { \"from\": \"\\u100b\\u1039\\u100b\", \"to\": \"\\u1097\" }, { \"from\": \"([\\u1000-\\u1021\\u108f\\u1029\\u106a\\u106e\\u106f\\u1086\\u1090\\u1091\\u1092\\u1097\\u1096])([\\u1060-\\u1069\\u106c\\u106d\\u1070-\\u107c\\u1085\\u108a])?([\\u103b-\\u103e]*)?\\u1031\", \"to\": \"\\u1031$1$2$3\" }, { \"from\": \"\\u103c\\u103e\", \"to\": \"\\u103c\\u1087\" }, { \"from\": \"([\\u1000-\\u1021\\u108f\\u1029])([\\u1060-\\u1069\\u106c\\u106d\\u1070-\\u107c\\u1085])?(\\u103c)\", \"to\": \"$3$1$2\" }, { \"from\": \"\\u103a\", \"to\": \"\\u1039\" }, { \"from\": \"\\u103b\", \"to\": \"\\u103a\" }, { \"from\": \"\\u103c\", \"to\": \"\\u103b\" }, { \"from\": \"\\u103d\", \"to\": \"\\u103c\" }, { \"from\": \"\\u103e\", \"to\": \"\\u103d\" }, { \"from\": \"([^\\u103a\\u100a])\\u103d([\\u102d\\u102e]?)\\u102f\", \"to\": \"$1\\u1088$2\" }, { \"from\": \"([\\u101b\\u103a\\u103c\\u108a\\u1088\\u1090])([\\u1030\\u103d])?([\\u1032\\u1036\\u1039\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e]?)(\\u102f)?\\u1037\", \"to\": \"$1$2$3$4\\u1095\" }, { \"from\": \"([\\u102f\\u1014\\u1030\\u103d])([\\u1032\\u1036\\u1039\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e]?)\\u1037\", \"to\": \"$1$2\\u1094\" }, { \"from\": \"([\\u103b])([\\u1000-\\u1021])([\\u1087]?)([\\u1036\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e]?)\\u102f\", \"to\": \"$1$2$3$4\\u1033\" }, { \"from\": \"([\\u103b])([\\u1000-\\u1021])([\\u1087]?)([\\u1036\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e]?)\\u1030\", \"to\": \"$1$2$3$4\\u1034\" }, { \"from\": \"([\\u103a\\u103c\\u100a\\u1008\\u100b\\u100c\\u100d\\u1020\\u1025])([\\u103d]?)([\\u1036\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e]?)\\u102f\", \"to\": \"$1$2$3\\u1033\" }, { \"from\": \"([\\u103a\\u103c\\u100a\\u1008\\u100b\\u100c\\u100d\\u1020\\u1025])(\\u103d?)([\\u1036\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e]?)\\u1030\", \"to\": \"$1$2$3\\u1034\" }, { \"from\": \"([\\u100a\\u1020\\u1009])\\u103d\", \"to\": \"$1\\u1087\" }, { \"from\": \"\\u103d\\u1030\", \"to\": \"\\u1089\" }, { \"from\": \"\\u103b([\\u1000\\u1003\\u1006\\u100f\\u1010\\u1011\\u1018\\u101a\\u101c\\u101a\\u101e\\u101f])\", \"to\": \"\\u107e$1\" }, { \"from\": \"\\u107e([\\u1000\\u1003\\u1006\\u100f\\u1010\\u1011\\u1018\\u101a\\u101c\\u101a\\u101e\\u101f])([\\u103c\\u108a])([\\u1032\\u1036\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e])\", \"to\": \"\\u1084$1$2$3\" }, { \"from\": \"\\u107e([\\u1000\\u1003\\u1006\\u100f\\u1010\\u1011\\u1018\\u101a\\u101c\\u101a\\u101e\\u101f])([\\u103c\\u108a])\", \"to\": \"\\u1082$1$2\" }, { \"from\": \"\\u107e([\\u1000\\u1003\\u1006\\u100f\\u1010\\u1011\\u1018\\u101a\\u101c\\u101a\\u101e\\u101f])([\\u1033\\u1034]?)([\\u1032\\u1036\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e])\", \"to\": \"\\u1080$1$2$3\" }, { \"from\": \"\\u103b([\\u1000-\\u1021])([\\u103c\\u108a])([\\u1032\\u1036\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e])\", \"to\": \"\\u1083$1$2$3\" }, { \"from\": \"\\u103b([\\u1000-\\u1021])([\\u103c\\u108a])\", \"to\": \"\\u1081$1$2\" }, { \"from\": \"\\u103b([\\u1000-\\u1021])([\\u1033\\u1034]?)([\\u1032\\u1036\\u102d\\u102e\\u108b\\u108c\\u108d\\u108e])\", \"to\": \"\\u107f$1$2$3\" }, { \"from\": \"\\u103a\\u103d\", \"to\": \"\\u103d\\u103a\" }, { \"from\": \"\\u103a([\\u103c\\u108a])\", \"to\": \"$1\\u107d\" }, { \"from\": \"([\\u1033\\u1034])(\\u1036?)\\u1094\", \"to\": \"$1$2\\u1095\" }, { \"from\": \"\\u108F\\u1071\", \"to\" : \"\\u108F\\u1072\" }, { \"from\": \"\\u108F\\u1073\", \"to\" : \"\\u108F\\u1074\" }, { \"from\": \"([\\u1000-\\u1021])([\\u107B\\u1066])\\u102C\", \"to\": \"$1\\u102C$2\" }, { \"from\": \"\\u102C([\\u107B\\u1066])\\u1037\", \"to\": \"\\u102C$1\\u1094\" }, { \"from\": \"\\u1047((?=[\\u1000-\\u1021]\\u1039)|(?=[\\u102c-\\u1030\\u1032\\u1036-\\u1038\\u103c\\u103d]))\", \"to\": \"\\u101b\" }]", true);
27 |
28 | return self::replaceWithRule($rule, $unicode);
29 | }
30 |
31 | /**
32 | * Convert zawgyi string to unicode.
33 | *
34 | * @param string $unicode
35 | * @return string
36 | */
37 | public static function zg2uni($zawgyi)
38 | {
39 | $rule = json_decode("[ { \"from\" : \"([\\u102D\\u102E\\u103D\\u102F\\u1037\\u1095])\\\\1+\", \"to\" : \"$1\" }, { \"from\": \"\\u200B\", \"to\": \"\" }, { \"from\" : \"\\u103d\\u103c\", \"to\" : \"\\u108a\" }, { \"from\": \"(\\u103d|\\u1087)\", \"to\": \"\\u103e\" }, { \"from\": \"\\u103c\", \"to\": \"\\u103d\" }, { \"from\": \"(\\u103b|\\u107e|\\u107f|\\u1080|\\u1081|\\u1082|\\u1083|\\u1084)\", \"to\": \"\\u103c\" }, { \"from\": \"(\\u103a|\\u107d)\", \"to\": \"\\u103b\" }, { \"from\": \"\\u1039\", \"to\": \"\\u103a\" }, { \"from\": \"(\\u1066|\\u1067)\", \"to\": \"\\u1039\\u1006\" }, { \"from\": \"\\u106a\", \"to\": \"\\u1009\" }, { \"from\": \"\\u106b\", \"to\": \"\\u100a\" }, { \"from\": \"\\u106c\", \"to\": \"\\u1039\\u100b\" }, { \"from\": \"\\u106d\", \"to\": \"\\u1039\\u100c\" }, { \"from\": \"\\u106e\", \"to\": \"\\u100d\\u1039\\u100d\" }, { \"from\": \"\\u106f\", \"to\": \"\\u100d\\u1039\\u100e\" }, { \"from\": \"\\u1070\", \"to\": \"\\u1039\\u100f\" }, { \"from\": \"(\\u1071|\\u1072)\", \"to\": \"\\u1039\\u1010\" }, { \"from\": \"\\u1060\", \"to\": \"\\u1039\\u1000\" }, { \"from\": \"\\u1061\", \"to\": \"\\u1039\\u1001\" }, { \"from\": \"\\u1062\", \"to\": \"\\u1039\\u1002\" }, { \"from\": \"\\u1063\", \"to\": \"\\u1039\\u1003\" }, { \"from\": \"\\u1065\", \"to\": \"\\u1039\\u1005\" }, { \"from\": \"\\u1068\", \"to\": \"\\u1039\\u1007\" }, { \"from\": \"\\u1069\", \"to\": \"\\u1039\\u1008\" }, { \"from\": \"(\\u1073|\\u1074)\", \"to\": \"\\u1039\\u1011\" }, { \"from\": \"\\u1075\", \"to\": \"\\u1039\\u1012\" }, { \"from\": \"\\u1076\", \"to\": \"\\u1039\\u1013\" }, { \"from\": \"\\u1077\", \"to\": \"\\u1039\\u1014\" }, { \"from\": \"\\u1078\", \"to\": \"\\u1039\\u1015\" }, { \"from\": \"\\u1079\", \"to\": \"\\u1039\\u1016\" }, { \"from\": \"\\u107a\", \"to\": \"\\u1039\\u1017\" }, { \"from\": \"\\u107c\", \"to\": \"\\u1039\\u1019\" }, { \"from\": \"\\u1085\", \"to\": \"\\u1039\\u101c\" }, { \"from\": \"\\u1033\", \"to\": \"\\u102f\" }, { \"from\": \"\\u1034\", \"to\": \"\\u1030\" }, { \"from\": \"\\u103f\", \"to\": \"\\u1030\" }, { \"from\": \"\\u1086\", \"to\": \"\\u103f\" }, { \"from\": \"\\u1036\\u1088\", \"to\": \"\\u1088\\u1036\" }, { \"from\": \"\\u1088\", \"to\": \"\\u103e\\u102f\" }, { \"from\": \"\\u1089\", \"to\": \"\\u103e\\u1030\" }, { \"from\": \"\\u108a\", \"to\": \"\\u103d\\u103e\" }, { \"from\": \"\\u103B\\u1064\", \"to\": \"\\u1064\\u103B\" }, { \"from\": \"\\u103c([\\u1000-\\u1021])([\\u1064\\u108b\\u108d])\", \"to\": \"$1\\u103c$2\" }, { \"from\": \"(\\u1031)?([\\u1000-\\u1021\\u1040-\\u1049])(\\u103c)?\\u1064\", \"to\": \"\\u1004\\u103a\\u1039$1$2$3\" }, { \"from\": \"(\\u1031)?([\\u1000-\\u1021])(\\u103b|\\u103c)?\\u108b\", \"to\": \"\\u1004\\u103a\\u1039$1$2$3\\u102d\" }, { \"from\": \"(\\u1031)?([\\u1000-\\u1021])(\\u103b)?\\u108c\", \"to\": \"\\u1004\\u103a\\u1039$1$2$3\\u102e\" }, { \"from\": \"(\\u1031)?([\\u1000-\\u1021])([\\u103b\\u103c])?\\u108d\", \"to\": \"\\u1004\\u103a\\u1039$1$2$3\\u1036\" }, { \"from\": \"\\u108e\", \"to\": \"\\u102d\\u1036\" }, { \"from\": \"\\u108f\", \"to\": \"\\u1014\" }, { \"from\": \"\\u1090\", \"to\": \"\\u101b\" }, { \"from\": \"\\u1091\", \"to\": \"\\u100f\\u1039\\u100d\" }, { \"from\": \"\\u1092\", \"to\": \"\\u100b\\u1039\\u100c\" }, { \"from\": \"\\u1019\\u102c(\\u107b|\\u1093)\", \"to\": \"\\u1019\\u1039\\u1018\\u102c\" }, { \"from\": \"(\\u107b|\\u1093)\", \"to\": \"\\u1039\\u1018\" }, { \"from\": \"(\\u1094|\\u1095)\", \"to\": \"\\u1037\" }, { \"from\": \"([\\u1000-\\u1021])\\u1037\\u1032\", \"to\": \"$1\\u1032\\u1037\" }, { \"from\": \"\\u1096\", \"to\": \"\\u1039\\u1010\\u103d\" }, { \"from\": \"\\u1097\", \"to\": \"\\u100b\\u1039\\u100b\" }, { \"from\": \"\\u103c([\\u1000-\\u1021])([\\u1000-\\u1021])?\", \"to\": \"$1\\u103c$2\" }, { \"from\": \"([\\u1000-\\u1021])\\u103c\\u103a\", \"to\": \"\\u103c$1\\u103a\" }, { \"from\": \"\\u1047(?=[\\u102c-\\u1030\\u1032\\u1036-\\u1038\\u103d\\u1038])\", \"to\": \"\\u101b\" }, { \"from\": \"\\u1031\\u1047\", \"to\": \"\\u1031\\u101b\" }, { \"from\": \"\\u1040(\\u102e|\\u102f|\\u102d\\u102f|\\u1030|\\u1036|\\u103d|\\u103e)\", \"to\": \"\\u101d$1\" }, { \"from\": \"([^\\u1040\\u1041\\u1042\\u1043\\u1044\\u1045\\u1046\\u1047\\u1048\\u1049])\\u1040\\u102b\", \"to\": \"$1\\u101d\\u102b\" }, { \"from\": \"([\\u1040\\u1041\\u1042\\u1043\\u1044\\u1045\\u1046\\u1047\\u1048\\u1049])\\u1040\\u102b(?!\\u1038)\", \"to\": \"$1\\u101d\\u102b\" }, { \"from\": \"^\\u1040(?=\\u102b)\", \"to\": \"\\u101d\" }, { \"from\": \"\\u1040\\u102d(?!\\u0020?/)\", \"to\": \"\\u101d\\u102d\" }, { \"from\": \"([^\\u1040-\\u1049])\\u1040([^\\u1040-\\u1049\\u0020]|[\\u104a\\u104b])\", \"to\": \"$1\\u101d$2\" }, { \"from\": \"([^\\u1040-\\u1049])\\u1040(?=[\\\\f\\\\n\\\\r])\", \"to\": \"$1\\u101d\" }, { \"from\": \"([^\\u1040-\\u1049])\\u1040$\", \"to\": \"$1\\u101d\" }, { \"from\": \"\\u1031([\\u1000-\\u1021\\u103f])(\\u103e)?(\\u103b)?\", \"to\": \"$1$2$3\\u1031\" }, { \"from\": \"([\\u1000-\\u1021])\\u1031([\\u103b\\u103c\\u103d\\u103e]+)\", \"to\": \"$1$2\\u1031\" }, { \"from\": \"\\u1032\\u103d\", \"to\": \"\\u103d\\u1032\" }, { \"from\": \"([\\u102d\\u102e])\\u103b\", \"to\": \"\\u103b$1\" }, { \"from\": \"\\u103d\\u103b\", \"to\": \"\\u103b\\u103d\" }, { \"from\": \"\\u103a\\u1037\", \"to\": \"\\u1037\\u103a\" }, { \"from\": \"\\u102f(\\u102d|\\u102e|\\u1036|\\u1037)\\u102f\", \"to\": \"\\u102f$1\" }, { \"from\": \"(\\u102f|\\u1030)(\\u102d|\\u102e)\", \"to\": \"$2$1\" }, { \"from\": \"(\\u103e)(\\u103b|\\u103c)\", \"to\": \"$2$1\" }, { \"from\": \"\\u1025(?=[\\u1037]?[\\u103a\\u102c])\", \"to\": \"\\u1009\" }, { \"from\": \"\\u1025\\u102e\", \"to\": \"\\u1026\" }, { \"from\": \"\\u1005\\u103b\", \"to\": \"\\u1008\" }, { \"from\": \"\\u1036(\\u102f|\\u1030)\", \"to\": \"$1\\u1036\" }, { \"from\": \"\\u1031\\u1037\\u103e\", \"to\": \"\\u103e\\u1031\\u1037\" }, { \"from\": \"\\u1031\\u103e\\u102c\", \"to\": \"\\u103e\\u1031\\u102c\" }, { \"from\": \"\\u105a\", \"to\": \"\\u102b\\u103a\" }, { \"from\": \"\\u1031\\u103b\\u103e\", \"to\": \"\\u103b\\u103e\\u1031\" }, { \"from\": \"(\\u102d|\\u102e)(\\u103d|\\u103e)\", \"to\": \"$2$1\" }, { \"from\": \"\\u102c\\u1039([\\u1000-\\u1021])\", \"to\": \"\\u1039$1\\u102c\" }, { \"from\": \"\\u1039\\u103c\\u103a\\u1039([\\u1000-\\u1021])\", \"to\": \"\\u103a\\u1039$1\\u103c\" }, { \"from\": \"\\u103c\\u1039([\\u1000-\\u1021])\", \"to\": \"\\u1039$1\\u103c\" }, { \"from\": \"\\u1036\\u1039([\\u1000-\\u1021])\", \"to\": \"\\u1039$1\\u1036\" }, { \"from\": \"\\u104e\", \"to\": \"\\u104e\\u1004\\u103a\\u1038\" }, { \"from\": \"\\u1040(\\u102b|\\u102c|\\u1036)\", \"to\": \"\\u101d$1\" }, { \"from\": \"\\u1025\\u1039\", \"to\": \"\\u1009\\u1039\" }, { \"from\": \"([\\u1000-\\u1021])\\u103c\\u1031\\u103d\", \"to\": \"$1\\u103c\\u103d\\u1031\" }, { \"from\": \"([\\u1000-\\u1021])\\u103b\\u1031\\u103d(\\u103e)?\", \"to\": \"$1\\u103b\\u103d$2\\u1031\" }, { \"from\": \"([\\u1000-\\u1021])\\u103d\\u1031\\u103b\", \"to\": \"$1\\u103b\\u103d\\u1031\" }, { \"from\": \"([\\u1000-\\u1021])\\u1031(\\u1039[\\u1000-\\u1021]\\u103d?)\", \"to\": \"$1$2\\u1031\" }, { \"from\": \"\\u1038\\u103a\", \"to\": \"\\u103a\\u1038\" }, { \"from\": \"\\u102d\\u103a|\\u103a\\u102d\", \"to\": \"\\u102d\" }, { \"from\": \"\\u102d\\u102f\\u103a\", \"to\": \"\\u102d\\u102f\" }, { \"from\": \"\\u0020\\u1037\", \"to\": \"\\u1037\" }, { \"from\": \"\\u1037\\u1036\", \"to\": \"\\u1036\\u1037\" }, { \"from\": \"[\\u102d]+\", \"to\": \"\\u102d\" }, { \"from\": \"[\\u103a]+\", \"to\": \"\\u103a\" }, { \"from\": \"[\\u103d]+\", \"to\": \"\\u103d\" }, { \"from\": \"[\\u1037]+\", \"to\": \"\\u1037\" }, { \"from\": \"[\\u102e]+\", \"to\": \"\\u102e\" }, { \"from\": \"\\u102d\\u102e|\\u102e\\u102d\", \"to\": \"\\u102e\" }, { \"from\": \"\\u102f\\u102d\", \"to\": \"\\u102d\\u102f\" }, { \"from\": \"\\u1037\\u1037\", \"to\": \"\\u1037\" }, { \"from\": \"\\u1032\\u1032\", \"to\": \"\\u1032\" }, { \"from\": \"\\u1044\\u1004\\u103a\\u1038\", \"to\": \"\\u104E\\u1004\\u103a\\u1038\" }, { \"from\": \"([\\u102d\\u102e])\\u1039([\\u1000-\\u1021])\", \"to\": \"\\u1039$2$1\" }, { \"from\": \"(\\u103c\\u1031)\\u1039([\\u1000-\\u1021])\", \"to\": \"\\u1039$2$1\" }, { \"from\": \"\\u1036\\u103d\", \"to\": \"\\u103d\\u1036\" }, { \"from\": \"\\u1047((?=[\\u1000-\\u1021]\\u103a)|(?=[\\u102c-\\u1030\\u1032\\u1036-\\u1038\\u103d\\u103e]))\", \"to\": \"\\u101b\" }]", true);
40 |
41 | return self::replaceWithRule($rule, $zawgyi);
42 | }
43 |
44 | /**
45 | * Replace the line break to character to parse the data correctly
46 | * @param string $string
47 | * @return string
48 | */
49 | private static function parseline($string){
50 | $string = str_replace(chr(10), "\\n", $string);
51 | $string = str_replace(chr(13), "\\n", $string);
52 | $string = str_replace("\f", "\\f", $string);
53 | return $string;
54 | }
55 |
56 | /**
57 | * Replace the string with rules.
58 | *
59 | * @param array $rule
60 | * @param string $output
61 | * @return string
62 | */
63 | protected static function replaceWithRule($rule, $output)
64 | {
65 | foreach ($rule as $data) {
66 |
67 | $from_json = $data["from"];
68 |
69 | //search line break.
70 | //if line break include , need to fix the line
71 | if (strpos($from_json, chr(13)) !== false) {
72 | $from_json = self::parseline($from_json);
73 | }
74 |
75 | $from = "~".json_decode('"'.$from_json.'"')."~u";
76 | $to = json_decode('"'.$data["to"].'"');
77 | $output = preg_replace($from, $to, $output);
78 | }
79 |
80 | return $output;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------