util_helper.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2016/12/21
  6. * Time: 下午4:06
  7. */
  8. require_once (BASE_DATA_PATH . '/api/phpqrcode/phpqrcode.php');
  9. class util
  10. {
  11. const min_memno = 500;
  12. const max_memno = 2000;
  13. const passwd = 'xmmz@lrlz';
  14. public static function member_avatar($path)
  15. {
  16. if (is_null($path) || empty($path)) {
  17. $img = 'female.png';
  18. return RESOURCE_SITE_URL . '/mobile/defimg/' . $img;
  19. }
  20. else {
  21. if (self::ishttp($path)) {
  22. $url = $path;
  23. } else {
  24. $url = UPLOAD_SITE_URL . "/shop/avatar{$path}";
  25. }
  26. return $url;
  27. }
  28. }
  29. public static function ishttp($path)
  30. {
  31. if(strncasecmp($path,"http://",strlen("http://")) == 0 || strncasecmp($path,"https://",strlen("https://")) == 0) {
  32. return true;
  33. } else {
  34. return false;
  35. }
  36. }
  37. public static function goods_thumb_image($path, $store_id)
  38. {
  39. return cthumb($path, 480, $store_id);
  40. }
  41. public static function goods_spec($item)
  42. {
  43. $keyval = unserialize($item);
  44. if($keyval == false) {
  45. return "";
  46. }
  47. foreach ($keyval as $key => $val) {
  48. return $val;
  49. }
  50. return "";
  51. }
  52. public static function nickname($nick, $mobile, $name)
  53. {
  54. if (isset($nick) && !empty($nick)) {
  55. return $nick;
  56. }
  57. if (isset($name) && !empty($name)) {
  58. return $name;
  59. }
  60. if (isset($mobile) && !empty($mobile)) {
  61. if (strlen($mobile) == 11) {
  62. return substr_replace($mobile, '****', 3, 4);
  63. }
  64. }
  65. return '';
  66. }
  67. public static function mem_no()
  68. {
  69. $number = self::mb_incr('member_no',1,self::min_memno);
  70. if($number > self::max_memno) {
  71. self::mb_del_incr('member_no');
  72. $start_number = mt_rand(self::min_memno,2 * self::min_memno);
  73. $number = self::mb_incr('member_no',1,$start_number);
  74. }
  75. return $number;
  76. }
  77. private static function mb_incr($key,$val,$def_value = 0)
  78. {
  79. return incrcache('global_incr',$key,$val,'mb_',$def_value);
  80. }
  81. private static function mb_del_incr($key)
  82. {
  83. return del_incr('global_incr',$key,'mb_');
  84. }
  85. public static function start_with($haystack, $needle)
  86. {
  87. $length = strlen($needle);
  88. return (substr($haystack, 0, $length) === $needle);
  89. }
  90. public static function end_with($haystack, $needle)
  91. {
  92. $length = strlen($needle);
  93. if ($length == 0) {
  94. return true;
  95. }
  96. return (substr($haystack, -$length) === $needle);
  97. }
  98. public static function imgsize($url)
  99. {
  100. if (util::start_with($url,BASE_SITE_URL) == false) {
  101. return @getimagesize($url);
  102. }
  103. else {
  104. $length = strlen(BASE_SITE_URL);
  105. $src = BASE_ROOT_PATH . substr($url, $length, strlen($url) - $length);
  106. $size = @getimagesize($src);
  107. if($size == false) {
  108. return @getimagesize($url);
  109. } else {
  110. return $size;
  111. }
  112. }
  113. }
  114. public static function http_add_params($url, $params)
  115. {
  116. if (!empty($params)) {
  117. $url = $url . (strpos($url, '?') ? '&' : '?') . (is_array($params) ? http_build_query($params) : $params);
  118. }
  119. return $url;
  120. }
  121. public static function from_wechat()
  122. {
  123. $agent = request_helper::http_useragent();
  124. $pos = strpos($agent,"MicroMessenger");
  125. if($pos === false) {
  126. return false;
  127. } else {
  128. return ($pos >= 0);
  129. }
  130. }
  131. public static function encrypt_data($plaintext)
  132. {
  133. return encrypt("{$plaintext}",util::passwd);
  134. }
  135. public static function decrypt_data($ciphertext)
  136. {
  137. return decrypt($ciphertext,util::passwd);
  138. }
  139. public static function qrcode($url,$name)
  140. {
  141. if(empty($url) || empty($name)) return false;
  142. $save_path = BASE_UPLOAD_PATH . DS.ATTACH_MQRCODE.DS . $name;
  143. QRcode::png($url,$save_path,QR_ECLEVEL_H);
  144. return $save_path;
  145. }
  146. public static function qrcode_path($url,$save_path)
  147. {
  148. if(empty($url) || empty($save_path)) return false;
  149. QRcode::png($url,$save_path,QR_ECLEVEL_H);
  150. return $save_path;
  151. }
  152. public static function base64url_encode($plainText)
  153. {
  154. $base64 = base64_encode($plainText);
  155. $base64url = strtr($base64, ['+' => '-','/' => '_','=' => ',']);
  156. return $base64url;
  157. }
  158. public static function base64url_decode($plainText)
  159. {
  160. $base64url = strtr($plainText, ['-' => '+','_' => '/',',' => '=']);
  161. $base64 = base64_decode($base64url);
  162. return $base64;
  163. }
  164. public static function first_day_secs($input)
  165. {
  166. return strtotime(date('Y-m-d',$input));
  167. }
  168. public static function last_day_secs($input)
  169. {
  170. return strtotime(date('Y-m-d',$input)) + 86399;
  171. }
  172. public static function ellipsis($input, $len = 12)
  173. {
  174. if(mb_strlen($input,'utf-8') >= $len) {
  175. $input = mb_substr($input,0,$len,'utf-8');
  176. $input.= "...";
  177. }
  178. return $input;
  179. }
  180. }
  181. class string_helper
  182. {
  183. /**
  184. * The cache of snake-cased words.
  185. *
  186. * @var array
  187. */
  188. protected static $snakeCache = [];
  189. /**
  190. * The cache of camel-cased words.
  191. *
  192. * @var array
  193. */
  194. protected static $camelCache = [];
  195. /**
  196. * The cache of studly-cased words.
  197. *
  198. * @var array
  199. */
  200. protected static $studlyCache = [];
  201. /**
  202. * Return the remainder of a string after a given value.
  203. *
  204. * @param string $subject
  205. * @param string $search
  206. * @return string
  207. */
  208. public static function after($subject, $search)
  209. {
  210. return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
  211. }
  212. /**
  213. * Transliterate a UTF-8 value to ASCII.
  214. *
  215. * @param string $value
  216. * @param string $language
  217. * @return string
  218. */
  219. public static function ascii($value, $language = 'en')
  220. {
  221. $languageSpecific = static::languageSpecificCharsArray($language);
  222. if (! is_null($languageSpecific)) {
  223. $value = str_replace($languageSpecific[0], $languageSpecific[1], $value);
  224. }
  225. foreach (static::charsArray() as $key => $val) {
  226. $value = str_replace($val, $key, $value);
  227. }
  228. return preg_replace('/[^\x20-\x7E]/u', '', $value);
  229. }
  230. /**
  231. * Get the portion of a string before a given value.
  232. *
  233. * @param string $subject
  234. * @param string $search
  235. * @return string
  236. */
  237. public static function before($subject, $search)
  238. {
  239. return $search === '' ? $subject : explode($search, $subject)[0];
  240. }
  241. /**
  242. * Convert a value to camel case.
  243. *
  244. * @param string $value
  245. * @return string
  246. */
  247. public static function camel($value)
  248. {
  249. if (isset(static::$camelCache[$value])) {
  250. return static::$camelCache[$value];
  251. }
  252. return static::$camelCache[$value] = lcfirst(static::studly($value));
  253. }
  254. /**
  255. * Determine if a given string contains a given substring.
  256. *
  257. * @param string $haystack
  258. * @param string|array $needles
  259. * @return bool
  260. */
  261. public static function contains($haystack, $needles)
  262. {
  263. foreach ((array) $needles as $needle) {
  264. if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
  265. return true;
  266. }
  267. }
  268. return false;
  269. }
  270. /**
  271. * Determine if a given string ends with a given substring.
  272. *
  273. * @param string $haystack
  274. * @param string|array $needles
  275. * @return bool
  276. */
  277. public static function endsWith($haystack, $needles)
  278. {
  279. foreach ((array) $needles as $needle) {
  280. if (substr($haystack, -strlen($needle)) === (string) $needle) {
  281. return true;
  282. }
  283. }
  284. return false;
  285. }
  286. /**
  287. * Cap a string with a single instance of a given value.
  288. *
  289. * @param string $value
  290. * @param string $cap
  291. * @return string
  292. */
  293. public static function finish($value, $cap)
  294. {
  295. $quoted = preg_quote($cap, '/');
  296. return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
  297. }
  298. /**
  299. * Determine if a given string matches a given pattern.
  300. *
  301. * @param string|array $pattern
  302. * @param string $value
  303. * @return bool
  304. */
  305. public static function is($pattern, $value)
  306. {
  307. $patterns = is_array($pattern) ? $pattern : (array) $pattern;
  308. if (empty($patterns)) {
  309. return false;
  310. }
  311. foreach ($patterns as $pattern) {
  312. // If the given value is an exact match we can of course return true right
  313. // from the beginning. Otherwise, we will translate asterisks and do an
  314. // actual pattern match against the two strings to see if they match.
  315. if ($pattern == $value) {
  316. return true;
  317. }
  318. $pattern = preg_quote($pattern, '#');
  319. // Asterisks are translated into zero-or-more regular expression wildcards
  320. // to make it convenient to check if the strings starts with the given
  321. // pattern such as "library/*", making any string check convenient.
  322. $pattern = str_replace('\*', '.*', $pattern);
  323. if (preg_match('#^'.$pattern.'\z#u', $value) === 1) {
  324. return true;
  325. }
  326. }
  327. return false;
  328. }
  329. /**
  330. * Convert a string to kebab case.
  331. *
  332. * @param string $value
  333. * @return string
  334. */
  335. public static function kebab($value)
  336. {
  337. return static::snake($value, '-');
  338. }
  339. /**
  340. * Return the length of the given string.
  341. *
  342. * @param string $value
  343. * @param string $encoding
  344. * @return int
  345. */
  346. public static function length($value, $encoding = null)
  347. {
  348. if ($encoding) {
  349. return mb_strlen($value, $encoding);
  350. }
  351. return mb_strlen($value);
  352. }
  353. /**
  354. * Limit the number of characters in a string.
  355. *
  356. * @param string $value
  357. * @param int $limit
  358. * @param string $end
  359. * @return string
  360. */
  361. public static function limit($value, $limit = 100, $end = '...')
  362. {
  363. if (mb_strwidth($value, 'UTF-8') <= $limit) {
  364. return $value;
  365. }
  366. return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
  367. }
  368. /**
  369. * Convert the given string to lower-case.
  370. *
  371. * @param string $value
  372. * @return string
  373. */
  374. public static function lower($value)
  375. {
  376. return mb_strtolower($value, 'UTF-8');
  377. }
  378. /**
  379. * Limit the number of words in a string.
  380. *
  381. * @param string $value
  382. * @param int $words
  383. * @param string $end
  384. * @return string
  385. */
  386. public static function words($value, $words = 100, $end = '...')
  387. {
  388. preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches);
  389. if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) {
  390. return $value;
  391. }
  392. return rtrim($matches[0]).$end;
  393. }
  394. /**
  395. * Parse a Class@method style callback into class and method.
  396. *
  397. * @param string $callback
  398. * @param string|null $default
  399. * @return array
  400. */
  401. public static function parseCallback($callback, $default = null)
  402. {
  403. return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default];
  404. }
  405. /**
  406. * Generate a more truly "random" alpha-numeric string.
  407. *
  408. * @param int $length
  409. * @return string
  410. */
  411. public static function random($length = 16)
  412. {
  413. $string = '';
  414. while (($len = strlen($string)) < $length) {
  415. $size = $length - $len;
  416. $bytes = random_bytes($size);
  417. $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
  418. }
  419. return $string;
  420. }
  421. /**
  422. * Replace a given value in the string sequentially with an array.
  423. *
  424. * @param string $search
  425. * @param array $replace
  426. * @param string $subject
  427. * @return string
  428. */
  429. public static function replaceArray($search, array $replace, $subject)
  430. {
  431. foreach ($replace as $value) {
  432. $subject = static::replaceFirst($search, $value, $subject);
  433. }
  434. return $subject;
  435. }
  436. /**
  437. * Replace the first occurrence of a given value in the string.
  438. *
  439. * @param string $search
  440. * @param string $replace
  441. * @param string $subject
  442. * @return string
  443. */
  444. public static function replaceFirst($search, $replace, $subject)
  445. {
  446. if ($search == '') {
  447. return $subject;
  448. }
  449. $position = strpos($subject, $search);
  450. if ($position !== false) {
  451. return substr_replace($subject, $replace, $position, strlen($search));
  452. }
  453. return $subject;
  454. }
  455. /**
  456. * Replace the last occurrence of a given value in the string.
  457. *
  458. * @param string $search
  459. * @param string $replace
  460. * @param string $subject
  461. * @return string
  462. */
  463. public static function replaceLast($search, $replace, $subject)
  464. {
  465. $position = strrpos($subject, $search);
  466. if ($position !== false) {
  467. return substr_replace($subject, $replace, $position, strlen($search));
  468. }
  469. return $subject;
  470. }
  471. /**
  472. * Begin a string with a single instance of a given value.
  473. *
  474. * @param string $value
  475. * @param string $prefix
  476. * @return string
  477. */
  478. public static function start($value, $prefix)
  479. {
  480. $quoted = preg_quote($prefix, '/');
  481. return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value);
  482. }
  483. /**
  484. * Convert the given string to upper-case.
  485. *
  486. * @param string $value
  487. * @return string
  488. */
  489. public static function upper($value)
  490. {
  491. return mb_strtoupper($value, 'UTF-8');
  492. }
  493. /**
  494. * Convert the given string to title case.
  495. *
  496. * @param string $value
  497. * @return string
  498. */
  499. public static function title($value)
  500. {
  501. return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
  502. }
  503. /**
  504. * Generate a URL friendly "slug" from a given string.
  505. *
  506. * @param string $title
  507. * @param string $separator
  508. * @param string $language
  509. * @return string
  510. */
  511. public static function slug($title, $separator = '-', $language = 'en')
  512. {
  513. $title = static::ascii($title, $language);
  514. // Convert all dashes/underscores into separator
  515. $flip = $separator == '-' ? '_' : '-';
  516. $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
  517. // Replace @ with the word 'at'
  518. $title = str_replace('@', $separator.'at'.$separator, $title);
  519. // Remove all characters that are not the separator, letters, numbers, or whitespace.
  520. $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title));
  521. // Replace all separator characters and whitespace by a single separator
  522. $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
  523. return trim($title, $separator);
  524. }
  525. /**
  526. * Convert a string to snake case.
  527. *
  528. * @param string $value
  529. * @param string $delimiter
  530. * @return string
  531. */
  532. public static function snake($value, $delimiter = '_')
  533. {
  534. $key = $value;
  535. if (isset(static::$snakeCache[$key][$delimiter])) {
  536. return static::$snakeCache[$key][$delimiter];
  537. }
  538. if (! ctype_lower($value)) {
  539. $value = preg_replace('/\s+/u', '', ucwords($value));
  540. $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
  541. }
  542. return static::$snakeCache[$key][$delimiter] = $value;
  543. }
  544. /**
  545. * Determine if a given string starts with a given substring.
  546. *
  547. * @param string $haystack
  548. * @param string|array $needles
  549. * @return bool
  550. */
  551. public static function starts_with($haystack, $needles)
  552. {
  553. foreach ((array) $needles as $needle) {
  554. if ($needle !== '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
  555. return true;
  556. }
  557. }
  558. return false;
  559. }
  560. /**
  561. * Convert a value to studly caps case.
  562. *
  563. * @param string $value
  564. * @return string
  565. */
  566. public static function studly($value)
  567. {
  568. $key = $value;
  569. if (isset(static::$studlyCache[$key])) {
  570. return static::$studlyCache[$key];
  571. }
  572. $value = ucwords(str_replace(['-', '_'], ' ', $value));
  573. return static::$studlyCache[$key] = str_replace(' ', '', $value);
  574. }
  575. /**
  576. * Returns the portion of string specified by the start and length parameters.
  577. *
  578. * @param string $string
  579. * @param int $start
  580. * @param int|null $length
  581. * @return string
  582. */
  583. public static function substr($string, $start, $length = null)
  584. {
  585. return mb_substr($string, $start, $length, 'UTF-8');
  586. }
  587. /**
  588. * Make a string's first character uppercase.
  589. *
  590. * @param string $string
  591. * @return string
  592. */
  593. public static function ucfirst($string)
  594. {
  595. return static::upper(static::substr($string, 0, 1)).static::substr($string, 1);
  596. }
  597. /**
  598. * Returns the replacements for the ascii method.
  599. *
  600. * Note: Adapted from Stringy\Stringy.
  601. *
  602. * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt
  603. *
  604. * @return array
  605. */
  606. protected static function charsArray()
  607. {
  608. static $charsArray;
  609. if (isset($charsArray)) {
  610. return $charsArray;
  611. }
  612. return $charsArray = [
  613. '0' => ['°', '₀', '۰', '0'],
  614. '1' => ['¹', '₁', '۱', '1'],
  615. '2' => ['²', '₂', '۲', '2'],
  616. '3' => ['³', '₃', '۳', '3'],
  617. '4' => ['⁴', '₄', '۴', '٤', '4'],
  618. '5' => ['⁵', '₅', '۵', '٥', '5'],
  619. '6' => ['⁶', '₆', '۶', '٦', '6'],
  620. '7' => ['⁷', '₇', '۷', '7'],
  621. '8' => ['⁸', '₈', '۸', '8'],
  622. '9' => ['⁹', '₉', '۹', '9'],
  623. 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا', 'a', 'ä'],
  624. 'b' => ['б', 'β', 'ب', 'ဗ', 'ბ', 'b'],
  625. 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ', 'c'],
  626. 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ', 'd'],
  627. 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ', 'e'],
  628. 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ', 'f'],
  629. 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ', 'g'],
  630. 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ', 'h'],
  631. 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ', 'ی', 'i'],
  632. 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج', 'j'],
  633. 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک', 'k'],
  634. 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ', 'l'],
  635. 'm' => ['м', 'μ', 'م', 'မ', 'მ', 'm'],
  636. 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ', 'n'],
  637. 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ', 'o', 'ö'],
  638. 'p' => ['п', 'π', 'ပ', 'პ', 'پ', 'p'],
  639. 'q' => ['ყ', 'q'],
  640. 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ', 'r'],
  641. 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს', 's'],
  642. 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ', 't'],
  643. 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ', 'u', 'ў', 'ü'],
  644. 'v' => ['в', 'ვ', 'ϐ', 'v'],
  645. 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ', 'w'],
  646. 'x' => ['χ', 'ξ', 'x'],
  647. 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ', 'y'],
  648. 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ', 'z'],
  649. 'aa' => ['ع', 'आ', 'آ'],
  650. 'ae' => ['æ', 'ǽ'],
  651. 'ai' => ['ऐ'],
  652. 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'],
  653. 'dj' => ['ђ', 'đ'],
  654. 'dz' => ['џ', 'ძ'],
  655. 'ei' => ['ऍ'],
  656. 'gh' => ['غ', 'ღ'],
  657. 'ii' => ['ई'],
  658. 'ij' => ['ij'],
  659. 'kh' => ['х', 'خ', 'ხ'],
  660. 'lj' => ['љ'],
  661. 'nj' => ['њ'],
  662. 'oe' => ['ö', 'œ', 'ؤ'],
  663. 'oi' => ['ऑ'],
  664. 'oii' => ['ऒ'],
  665. 'ps' => ['ψ'],
  666. 'sh' => ['ш', 'შ', 'ش'],
  667. 'shch' => ['щ'],
  668. 'ss' => ['ß'],
  669. 'sx' => ['ŝ'],
  670. 'th' => ['þ', 'ϑ', 'ث', 'ذ', 'ظ'],
  671. 'ts' => ['ц', 'ც', 'წ'],
  672. 'ue' => ['ü'],
  673. 'uu' => ['ऊ'],
  674. 'ya' => ['я'],
  675. 'yu' => ['ю'],
  676. 'zh' => ['ж', 'ჟ', 'ژ'],
  677. '(c)' => ['©'],
  678. 'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ', 'A', 'Ä'],
  679. 'B' => ['Б', 'Β', 'ब', 'B'],
  680. 'C' => ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ', 'C'],
  681. 'D' => ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ', 'D'],
  682. 'E' => ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə', 'E'],
  683. 'F' => ['Ф', 'Φ', 'F'],
  684. 'G' => ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ', 'G'],
  685. 'H' => ['Η', 'Ή', 'Ħ', 'H'],
  686. 'I' => ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ', 'I'],
  687. 'J' => ['J'],
  688. 'K' => ['К', 'Κ', 'K'],
  689. 'L' => ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल', 'L'],
  690. 'M' => ['М', 'Μ', 'M'],
  691. 'N' => ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν', 'N'],
  692. 'O' => ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ', 'O', 'Ö'],
  693. 'P' => ['П', 'Π', 'P'],
  694. 'Q' => ['Q'],
  695. 'R' => ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ', 'R'],
  696. 'S' => ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ', 'S'],
  697. 'T' => ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ', 'T'],
  698. 'U' => ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ', 'U', 'Ў', 'Ü'],
  699. 'V' => ['В', 'V'],
  700. 'W' => ['Ω', 'Ώ', 'Ŵ', 'W'],
  701. 'X' => ['Χ', 'Ξ', 'X'],
  702. 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ', 'Y'],
  703. 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ', 'Z'],
  704. 'AE' => ['Æ', 'Ǽ'],
  705. 'Ch' => ['Ч'],
  706. 'Dj' => ['Ђ'],
  707. 'Dz' => ['Џ'],
  708. 'Gx' => ['Ĝ'],
  709. 'Hx' => ['Ĥ'],
  710. 'Ij' => ['IJ'],
  711. 'Jx' => ['Ĵ'],
  712. 'Kh' => ['Х'],
  713. 'Lj' => ['Љ'],
  714. 'Nj' => ['Њ'],
  715. 'Oe' => ['Œ'],
  716. 'Ps' => ['Ψ'],
  717. 'Sh' => ['Ш'],
  718. 'Shch' => ['Щ'],
  719. 'Ss' => ['ẞ'],
  720. 'Th' => ['Þ'],
  721. 'Ts' => ['Ц'],
  722. 'Ya' => ['Я'],
  723. 'Yu' => ['Ю'],
  724. 'Zh' => ['Ж'],
  725. ' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80", "\xEF\xBE\xA0"],
  726. ];
  727. }
  728. /**
  729. * Returns the language specific replacements for the ascii method.
  730. *
  731. * Note: Adapted from Stringy\Stringy.
  732. *
  733. * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt
  734. *
  735. * @param string $language
  736. * @return array|null
  737. */
  738. protected static function languageSpecificCharsArray($language)
  739. {
  740. static $languageSpecific;
  741. if (! isset($languageSpecific)) {
  742. $languageSpecific = [
  743. 'bg' => [
  744. ['х', 'Х', 'щ', 'Щ', 'ъ', 'Ъ', 'ь', 'Ь'],
  745. ['h', 'H', 'sht', 'SHT', 'a', 'А', 'y', 'Y'],
  746. ],
  747. 'de' => [
  748. ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'],
  749. ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'],
  750. ],
  751. ];
  752. }
  753. return $languageSpecific[$language] ? $languageSpecific[$language] : null;
  754. }
  755. }