util_helper.php 27 KB

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