util_helper.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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. public static function real_ip()
  181. {
  182. if (isset($_SERVER)) {
  183. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  184. $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  185. foreach ($arr as $ip) {
  186. $ip = trim($ip);
  187. if ($ip != 'unknown') {
  188. $realip = $ip;
  189. break;
  190. }
  191. }
  192. } else if (isset($_SERVER['HTTP_CLIENT_IP'])) {
  193. $realip = $_SERVER['HTTP_CLIENT_IP'];
  194. } else if (isset($_SERVER['REMOTE_ADDR'])) {
  195. $realip = $_SERVER['REMOTE_ADDR'];
  196. } else {
  197. $realip = '0.0.0.0';
  198. }
  199. } else if (getenv('HTTP_X_FORWARDED_FOR')) {
  200. $realip = getenv('HTTP_X_FORWARDED_FOR');
  201. } else if (getenv('HTTP_CLIENT_IP')) {
  202. $realip = getenv('HTTP_CLIENT_IP');
  203. } else {
  204. $realip = getenv('REMOTE_ADDR');
  205. }
  206. preg_match('/[\\d\\.]{7,15}/', $realip, $onlineip);
  207. $realip = (!empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0');
  208. return $realip;
  209. }
  210. }
  211. class string_helper
  212. {
  213. /**
  214. * The cache of snake-cased words.
  215. *
  216. * @var array
  217. */
  218. protected static $snakeCache = [];
  219. /**
  220. * The cache of camel-cased words.
  221. *
  222. * @var array
  223. */
  224. protected static $camelCache = [];
  225. /**
  226. * The cache of studly-cased words.
  227. *
  228. * @var array
  229. */
  230. protected static $studlyCache = [];
  231. /**
  232. * Return the remainder of a string after a given value.
  233. *
  234. * @param string $subject
  235. * @param string $search
  236. * @return string
  237. */
  238. public static function after($subject, $search)
  239. {
  240. return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
  241. }
  242. /**
  243. * Transliterate a UTF-8 value to ASCII.
  244. *
  245. * @param string $value
  246. * @param string $language
  247. * @return string
  248. */
  249. public static function ascii($value, $language = 'en')
  250. {
  251. $languageSpecific = static::languageSpecificCharsArray($language);
  252. if (! is_null($languageSpecific)) {
  253. $value = str_replace($languageSpecific[0], $languageSpecific[1], $value);
  254. }
  255. foreach (static::charsArray() as $key => $val) {
  256. $value = str_replace($val, $key, $value);
  257. }
  258. return preg_replace('/[^\x20-\x7E]/u', '', $value);
  259. }
  260. /**
  261. * Get the portion of a string before a given value.
  262. *
  263. * @param string $subject
  264. * @param string $search
  265. * @return string
  266. */
  267. public static function before($subject, $search)
  268. {
  269. return $search === '' ? $subject : explode($search, $subject)[0];
  270. }
  271. /**
  272. * Convert a value to camel case.
  273. *
  274. * @param string $value
  275. * @return string
  276. */
  277. public static function camel($value)
  278. {
  279. if (isset(static::$camelCache[$value])) {
  280. return static::$camelCache[$value];
  281. }
  282. return static::$camelCache[$value] = lcfirst(static::studly($value));
  283. }
  284. /**
  285. * Determine if a given string contains a given substring.
  286. *
  287. * @param string $haystack
  288. * @param string|array $needles
  289. * @return bool
  290. */
  291. public static function contains($haystack, $needles)
  292. {
  293. foreach ((array) $needles as $needle) {
  294. if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
  295. return true;
  296. }
  297. }
  298. return false;
  299. }
  300. /**
  301. * Determine if a given string ends with a given substring.
  302. *
  303. * @param string $haystack
  304. * @param string|array $needles
  305. * @return bool
  306. */
  307. public static function endsWith($haystack, $needles)
  308. {
  309. foreach ((array) $needles as $needle) {
  310. if (substr($haystack, -strlen($needle)) === (string) $needle) {
  311. return true;
  312. }
  313. }
  314. return false;
  315. }
  316. /**
  317. * Cap a string with a single instance of a given value.
  318. *
  319. * @param string $value
  320. * @param string $cap
  321. * @return string
  322. */
  323. public static function finish($value, $cap)
  324. {
  325. $quoted = preg_quote($cap, '/');
  326. return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
  327. }
  328. /**
  329. * Determine if a given string matches a given pattern.
  330. *
  331. * @param string|array $pattern
  332. * @param string $value
  333. * @return bool
  334. */
  335. public static function is($pattern, $value)
  336. {
  337. $patterns = is_array($pattern) ? $pattern : (array) $pattern;
  338. if (empty($patterns)) {
  339. return false;
  340. }
  341. foreach ($patterns as $pattern) {
  342. // If the given value is an exact match we can of course return true right
  343. // from the beginning. Otherwise, we will translate asterisks and do an
  344. // actual pattern match against the two strings to see if they match.
  345. if ($pattern == $value) {
  346. return true;
  347. }
  348. $pattern = preg_quote($pattern, '#');
  349. // Asterisks are translated into zero-or-more regular expression wildcards
  350. // to make it convenient to check if the strings starts with the given
  351. // pattern such as "library/*", making any string check convenient.
  352. $pattern = str_replace('\*', '.*', $pattern);
  353. if (preg_match('#^'.$pattern.'\z#u', $value) === 1) {
  354. return true;
  355. }
  356. }
  357. return false;
  358. }
  359. /**
  360. * Convert a string to kebab case.
  361. *
  362. * @param string $value
  363. * @return string
  364. */
  365. public static function kebab($value)
  366. {
  367. return static::snake($value, '-');
  368. }
  369. /**
  370. * Return the length of the given string.
  371. *
  372. * @param string $value
  373. * @param string $encoding
  374. * @return int
  375. */
  376. public static function length($value, $encoding = null)
  377. {
  378. if ($encoding) {
  379. return mb_strlen($value, $encoding);
  380. }
  381. return mb_strlen($value);
  382. }
  383. /**
  384. * Limit the number of characters in a string.
  385. *
  386. * @param string $value
  387. * @param int $limit
  388. * @param string $end
  389. * @return string
  390. */
  391. public static function limit($value, $limit = 100, $end = '...')
  392. {
  393. if (mb_strwidth($value, 'UTF-8') <= $limit) {
  394. return $value;
  395. }
  396. return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
  397. }
  398. /**
  399. * Convert the given string to lower-case.
  400. *
  401. * @param string $value
  402. * @return string
  403. */
  404. public static function lower($value)
  405. {
  406. return mb_strtolower($value, 'UTF-8');
  407. }
  408. /**
  409. * Limit the number of words in a string.
  410. *
  411. * @param string $value
  412. * @param int $words
  413. * @param string $end
  414. * @return string
  415. */
  416. public static function words($value, $words = 100, $end = '...')
  417. {
  418. preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches);
  419. if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) {
  420. return $value;
  421. }
  422. return rtrim($matches[0]).$end;
  423. }
  424. /**
  425. * Parse a Class@method style callback into class and method.
  426. *
  427. * @param string $callback
  428. * @param string|null $default
  429. * @return array
  430. */
  431. public static function parseCallback($callback, $default = null)
  432. {
  433. return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default];
  434. }
  435. /**
  436. * Generate a more truly "random" alpha-numeric string.
  437. *
  438. * @param int $length
  439. * @return string
  440. */
  441. public static function random($length = 16)
  442. {
  443. $string = '';
  444. while (($len = strlen($string)) < $length) {
  445. $size = $length - $len;
  446. $bytes = random_bytes($size);
  447. $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
  448. }
  449. return $string;
  450. }
  451. /**
  452. * Replace a given value in the string sequentially with an array.
  453. *
  454. * @param string $search
  455. * @param array $replace
  456. * @param string $subject
  457. * @return string
  458. */
  459. public static function replaceArray($search, array $replace, $subject)
  460. {
  461. foreach ($replace as $value) {
  462. $subject = static::replaceFirst($search, $value, $subject);
  463. }
  464. return $subject;
  465. }
  466. /**
  467. * Replace the first occurrence of a given value in the string.
  468. *
  469. * @param string $search
  470. * @param string $replace
  471. * @param string $subject
  472. * @return string
  473. */
  474. public static function replaceFirst($search, $replace, $subject)
  475. {
  476. if ($search == '') {
  477. return $subject;
  478. }
  479. $position = strpos($subject, $search);
  480. if ($position !== false) {
  481. return substr_replace($subject, $replace, $position, strlen($search));
  482. }
  483. return $subject;
  484. }
  485. /**
  486. * Replace the last occurrence of a given value in the string.
  487. *
  488. * @param string $search
  489. * @param string $replace
  490. * @param string $subject
  491. * @return string
  492. */
  493. public static function replaceLast($search, $replace, $subject)
  494. {
  495. $position = strrpos($subject, $search);
  496. if ($position !== false) {
  497. return substr_replace($subject, $replace, $position, strlen($search));
  498. }
  499. return $subject;
  500. }
  501. /**
  502. * Begin a string with a single instance of a given value.
  503. *
  504. * @param string $value
  505. * @param string $prefix
  506. * @return string
  507. */
  508. public static function start($value, $prefix)
  509. {
  510. $quoted = preg_quote($prefix, '/');
  511. return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value);
  512. }
  513. /**
  514. * Convert the given string to upper-case.
  515. *
  516. * @param string $value
  517. * @return string
  518. */
  519. public static function upper($value)
  520. {
  521. return mb_strtoupper($value, 'UTF-8');
  522. }
  523. /**
  524. * Convert the given string to title case.
  525. *
  526. * @param string $value
  527. * @return string
  528. */
  529. public static function title($value)
  530. {
  531. return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
  532. }
  533. /**
  534. * Generate a URL friendly "slug" from a given string.
  535. *
  536. * @param string $title
  537. * @param string $separator
  538. * @param string $language
  539. * @return string
  540. */
  541. public static function slug($title, $separator = '-', $language = 'en')
  542. {
  543. $title = static::ascii($title, $language);
  544. // Convert all dashes/underscores into separator
  545. $flip = $separator == '-' ? '_' : '-';
  546. $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
  547. // Replace @ with the word 'at'
  548. $title = str_replace('@', $separator.'at'.$separator, $title);
  549. // Remove all characters that are not the separator, letters, numbers, or whitespace.
  550. $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title));
  551. // Replace all separator characters and whitespace by a single separator
  552. $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
  553. return trim($title, $separator);
  554. }
  555. /**
  556. * Convert a string to snake case.
  557. *
  558. * @param string $value
  559. * @param string $delimiter
  560. * @return string
  561. */
  562. public static function snake($value, $delimiter = '_')
  563. {
  564. $key = $value;
  565. if (isset(static::$snakeCache[$key][$delimiter])) {
  566. return static::$snakeCache[$key][$delimiter];
  567. }
  568. if (! ctype_lower($value)) {
  569. $value = preg_replace('/\s+/u', '', ucwords($value));
  570. $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
  571. }
  572. return static::$snakeCache[$key][$delimiter] = $value;
  573. }
  574. /**
  575. * Determine if a given string starts with a given substring.
  576. *
  577. * @param string $haystack
  578. * @param string|array $needles
  579. * @return bool
  580. */
  581. public static function starts_with($haystack, $needles)
  582. {
  583. foreach ((array) $needles as $needle) {
  584. if ($needle !== '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
  585. return true;
  586. }
  587. }
  588. return false;
  589. }
  590. /**
  591. * Convert a value to studly caps case.
  592. *
  593. * @param string $value
  594. * @return string
  595. */
  596. public static function studly($value)
  597. {
  598. $key = $value;
  599. if (isset(static::$studlyCache[$key])) {
  600. return static::$studlyCache[$key];
  601. }
  602. $value = ucwords(str_replace(['-', '_'], ' ', $value));
  603. return static::$studlyCache[$key] = str_replace(' ', '', $value);
  604. }
  605. /**
  606. * Returns the portion of string specified by the start and length parameters.
  607. *
  608. * @param string $string
  609. * @param int $start
  610. * @param int|null $length
  611. * @return string
  612. */
  613. public static function substr($string, $start, $length = null)
  614. {
  615. return mb_substr($string, $start, $length, 'UTF-8');
  616. }
  617. /**
  618. * Make a string's first character uppercase.
  619. *
  620. * @param string $string
  621. * @return string
  622. */
  623. public static function ucfirst($string)
  624. {
  625. return static::upper(static::substr($string, 0, 1)).static::substr($string, 1);
  626. }
  627. /**
  628. * Returns the replacements for the ascii method.
  629. *
  630. * Note: Adapted from Stringy\Stringy.
  631. *
  632. * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt
  633. *
  634. * @return array
  635. */
  636. protected static function charsArray()
  637. {
  638. static $charsArray;
  639. if (isset($charsArray)) {
  640. return $charsArray;
  641. }
  642. return $charsArray = [
  643. '0' => ['°', '₀', '۰', '0'],
  644. '1' => ['¹', '₁', '۱', '1'],
  645. '2' => ['²', '₂', '۲', '2'],
  646. '3' => ['³', '₃', '۳', '3'],
  647. '4' => ['⁴', '₄', '۴', '٤', '4'],
  648. '5' => ['⁵', '₅', '۵', '٥', '5'],
  649. '6' => ['⁶', '₆', '۶', '٦', '6'],
  650. '7' => ['⁷', '₇', '۷', '7'],
  651. '8' => ['⁸', '₈', '۸', '8'],
  652. '9' => ['⁹', '₉', '۹', '9'],
  653. 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا', 'a', 'ä'],
  654. 'b' => ['б', 'β', 'ب', 'ဗ', 'ბ', 'b'],
  655. 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ', 'c'],
  656. 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ', 'd'],
  657. 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ', 'e'],
  658. 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ', 'f'],
  659. 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ', 'g'],
  660. 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ', 'h'],
  661. 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ', 'ی', 'i'],
  662. 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج', 'j'],
  663. 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک', 'k'],
  664. 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ', 'l'],
  665. 'm' => ['м', 'μ', 'م', 'မ', 'მ', 'm'],
  666. 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ', 'n'],
  667. 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ', 'o', 'ö'],
  668. 'p' => ['п', 'π', 'ပ', 'პ', 'پ', 'p'],
  669. 'q' => ['ყ', 'q'],
  670. 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ', 'r'],
  671. 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს', 's'],
  672. 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ', 't'],
  673. 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ', 'u', 'ў', 'ü'],
  674. 'v' => ['в', 'ვ', 'ϐ', 'v'],
  675. 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ', 'w'],
  676. 'x' => ['χ', 'ξ', 'x'],
  677. 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ', 'y'],
  678. 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ', 'z'],
  679. 'aa' => ['ع', 'आ', 'آ'],
  680. 'ae' => ['æ', 'ǽ'],
  681. 'ai' => ['ऐ'],
  682. 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'],
  683. 'dj' => ['ђ', 'đ'],
  684. 'dz' => ['џ', 'ძ'],
  685. 'ei' => ['ऍ'],
  686. 'gh' => ['غ', 'ღ'],
  687. 'ii' => ['ई'],
  688. 'ij' => ['ij'],
  689. 'kh' => ['х', 'خ', 'ხ'],
  690. 'lj' => ['љ'],
  691. 'nj' => ['њ'],
  692. 'oe' => ['ö', 'œ', 'ؤ'],
  693. 'oi' => ['ऑ'],
  694. 'oii' => ['ऒ'],
  695. 'ps' => ['ψ'],
  696. 'sh' => ['ш', 'შ', 'ش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ų', 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ', 'U', 'Ў', 'Ü'],
  729. 'V' => ['В', 'V'],
  730. 'W' => ['Ω', 'Ώ', 'Ŵ', 'W'],
  731. 'X' => ['Χ', 'Ξ', 'X'],
  732. 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ', 'Y'],
  733. 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ', 'Z'],
  734. 'AE' => ['Æ', 'Ǽ'],
  735. 'Ch' => ['Ч'],
  736. 'Dj' => ['Ђ'],
  737. 'Dz' => ['Џ'],
  738. 'Gx' => ['Ĝ'],
  739. 'Hx' => ['Ĥ'],
  740. 'Ij' => ['IJ'],
  741. 'Jx' => ['Ĵ'],
  742. 'Kh' => ['Х'],
  743. 'Lj' => ['Љ'],
  744. 'Nj' => ['Њ'],
  745. 'Oe' => ['Œ'],
  746. 'Ps' => ['Ψ'],
  747. 'Sh' => ['Ш'],
  748. 'Shch' => ['Щ'],
  749. 'Ss' => ['ẞ'],
  750. 'Th' => ['Þ'],
  751. 'Ts' => ['Ц'],
  752. 'Ya' => ['Я'],
  753. 'Yu' => ['Ю'],
  754. 'Zh' => ['Ж'],
  755. ' ' => ["\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"],
  756. ];
  757. }
  758. /**
  759. * Returns the language specific replacements for the ascii method.
  760. *
  761. * Note: Adapted from Stringy\Stringy.
  762. *
  763. * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt
  764. *
  765. * @param string $language
  766. * @return array|null
  767. */
  768. protected static function languageSpecificCharsArray($language)
  769. {
  770. static $languageSpecific;
  771. if (! isset($languageSpecific)) {
  772. $languageSpecific = [
  773. 'bg' => [
  774. ['х', 'Х', 'щ', 'Щ', 'ъ', 'Ъ', 'ь', 'Ь'],
  775. ['h', 'H', 'sht', 'SHT', 'a', 'А', 'y', 'Y'],
  776. ],
  777. 'de' => [
  778. ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'],
  779. ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'],
  780. ],
  781. ];
  782. }
  783. return $languageSpecific[$language] ? $languageSpecific[$language] : null;
  784. }
  785. }