Skip to content

PHP support for UTF-8 including emoji. Working with a string.

License

Notifications You must be signed in to change notification settings

alfredleo/SimpleSolutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP support for UTF-8 including emoji. Working with a string.

Simple solutions are not so simple...

Stress tests were taken from what-are-the-most-difficult-to-render-unicode-samples.

Read more here:

Tests to run:

<?php
// winner function to reverse any string in php
function reverse5($string)
{
    if (!extension_loaded('intl')) {
        return 'intl extension is not loaded';
    }
    $length = grapheme_strlen($string);
    $ret = [];
    for ($i = $length; $i >= 0; $i -= 1) {
        $ret[] = grapheme_substr($string, $i, 1);
    }
    return implode($ret);
}

echo '<pre>';
testMe("ŎŏĞğÇ窺ЎўҒғЧчШш‘", "‘шШчЧғҒўЎşŞçÇğĞŏŎ"); // uzbek problematic letters test
testMe('Hello from github', 'buhtig morf olleH');
testMe("\r\n", "\r\n");
testMe('', '');
testMe('1', '1');
testMe('ab', 'ba');
testMe('тест по UTF8', '8FTU оп тсет');
testMe('اهلا بك', 'كب الها');
testMe('👹👺💀👻', '👻💀👺👹');
testMe("abca\xCC\x8Ao\xCC\x88", 'öåcba');
testMe("\u{1000}\u{1F7C9}\u{12043}𒁂\u{12042}\u{12030}\u{12031}\u{10ffff}", '�𒀱𒀰𒁂𒁂𒁃🟉က');
echo 'Vertically-stacked characters:';
testMe('Z̤͔ͧ̑̓ä͖̭̈̇lͮ̒ͫǧ̗͚̚o̙̔ͮ̇͐̇', 'o̙̔ͮ̇͐̇ǧ̗͚̚lͮ̒ͫä͖̭̈̇Z̤͔ͧ̑̓');
echo 'Right-to-left words:';
testMe('اختبار النص', 'صنلا رابتخا');
echo 'Mixed-direction words:';
testMe('من left اليمين to الى right اليسار', 'راسيلا thgir ىلا ot نيميلا tfel نم');
echo 'Mixed-direction characters:';
testMe('a‭b‮c‭d‮e‭f‮g', 'g‮f‭e‮d‭c‮b‭a');
echo 'Very long characters:';
testMe('﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽', '﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽﷽');
testMe('👭👬⚧⚥⚣⚢⚤', '⚤⚢⚣⚥⚧👬👭');
echo 'Emoji with skintone variations:';
testMe('👱👱🏻👱🏼👱🏽👱🏾👱🏿', '👱🏿👱🏾👱🏽👱🏼👱🏻👱');
echo 'Emoji with sex variations:';
testMe('🧟‍♀️🧟‍♂️', '🧟‍♂️🧟‍♀️');
echo 'Apple-invented combined emoji:';
testMe('👨‍❤️‍💋‍👨👩‍👩‍👧‍👦', '👩‍👩‍👧‍👦👨‍❤️‍💋‍👨');
echo '</pre>';

TODO:

  • Need real tests with double reverse and string comparison.
  • None of the function work well with sex emoji variations.

About

PHP support for UTF-8 including emoji. Working with a string.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages