Advertisement
xladomaz

Text to DIscord Smile

Dec 2nd, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. function textToSmile($s) {
  2.   $arr = array();    
  3.   $s = (string) $s;
  4.   $s = str_replace(array("\n", "\r"), " ", $s);
  5.   $s = trim($s);
  6.   $s = function_exists('mb_strtolower') ? mb_strtolower($s) : strtolower($s);
  7.   $s = strtr($s, array('а'=>'a','б'=>'b','в'=>'v','г'=>'g','д'=>'d','е'=>'e','ё'=>'e','ж'=>'j','з'=>'z','и'=>'i','й'=>'y','к'=>'k','л'=>'l','м'=>'m','н'=>'n','о'=>'o','п'=>'p','р'=>'r','с'=>'s','т'=>'t','у'=>'u','ф'=>'f','х'=>'h','ц'=>'c','ч'=>'ch','ш'=>'sh','щ'=>'shch','ы'=>'y','э'=>'e','ю'=>'yu','я'=>'ya','ъ'=>'','ь'=>''));
  8.   $s = preg_replace("/[^0-9a-z-_ ]/i", "", $s);
  9.   $s = preg_split('//u', $s, -1, PREG_SPLIT_NO_EMPTY);
  10.   foreach($s as $value) {
  11.       if($value == " ") {
  12.          $arr[] = ":heart:";
  13.       }else {
  14.           $arr[] = ":regional_indicator_" . $value . ": ";
  15.       }
  16.   }
  17.   return implode("", $arr);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement