snipt

Ctrl+h for KB shortcuts

PHP

Friendly URL

function url_slug($str, $options = array()) {
	// Make sure string is in UTF-8 and strip invalid UTF-8 characters
	$str = mb_convert_encoding((string)$str, 'UTF-8', mb_list_encodings());
	
	$defaults = array(
		'delimiter' => '-',
		'limit' => null,
		'lowercase' => false,
		'replacements' => array(),
		'transliterate' => false,
	);
	
	// Merge options
	$options = array_merge($defaults, $options);
	
	$char_map = array(
		// Latin
		'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C', 
		'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 
		'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ő' => 'O', 
		'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', 'Ý' => 'Y', 'Þ' => 'TH', 
		'ß' => 'ss', 
		'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 
		'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 
		'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o', 
		'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th', 
		'ÿ' => 'y',
 
		// Latin symbols
		'©' => '(c)',
 
		// Greek
		'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8',
		'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P',
		'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W',
		'Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y', 'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I',
		'Ϋ' => 'Y',
		'α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8',
		'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p',
		'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w',
		'ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's',
		'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i',
 
		// Turkish
		'Ş' => 'S', 'İ' => 'I', 'Ç' => 'C', 'Ü' => 'U', 'Ö' => 'O', 'Ğ' => 'G',
		'ş' => 's', 'ı' => 'i', 'ç' => 'c', 'ü' => 'u', 'ö' => 'o', 'ğ' => 'g', 
 
		// Russian
		'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh',
		'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O',
		'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C',
		'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sh', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu',
		'Я' => 'Ya',
		'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh',
		'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o',
		'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c',
		'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sh', 'ъ' => '', 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'yu',
		'я' => 'ya',
 
		// Ukrainian
		'Є' => 'Ye', 'І' => 'I', 'Ї' => 'Yi', 'Ґ' => 'G',
		'є' => 'ye', 'і' => 'i', 'ї' => 'yi', 'ґ' => 'g',
 
		// Czech
		'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ň' => 'N', 'Ř' => 'R', 'Š' => 'S', 'Ť' => 'T', 'Ů' => 'U', 
		'Ž' => 'Z', 
		'č' => 'c', 'ď' => 'd', 'ě' => 'e', 'ň' => 'n', 'ř' => 'r', 'š' => 's', 'ť' => 't', 'ů' => 'u',
		'ž' => 'z', 
 
		// Polish
		'Ą' => 'A', 'Ć' => 'C', 'Ę' => 'e', 'Ł' => 'L', 'Ń' => 'N', 'Ó' => 'o', 'Ś' => 'S', 'Ź' => 'Z', 
		'Ż' => 'Z', 
		'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z',
		'ż' => 'z',
 
		// Latvian
		'Ā' => 'A', 'Č' => 'C', 'Ē' => 'E', 'Ģ' => 'G', 'Ī' => 'i', 'Ķ' => 'k', 'Ļ' => 'L', 'Ņ' => 'N', 
		'Š' => 'S', 'Ū' => 'u', 'Ž' => 'Z',
		'ā' => 'a', 'č' => 'c', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n',
		'š' => 's', 'ū' => 'u', 'ž' => 'z'
	);
	
	// Make custom replacements
	$str = preg_replace(array_keys($options['replacements']), $options['replacements'], $str);
	
	// Transliterate characters to ASCII
	if ($options['transliterate']) {
		$str = str_replace(array_keys($char_map), $char_map, $str);
	}
	
	// Replace non-alphanumeric characters with our delimiter
	$str = preg_replace('/[^\p{L}\p{Nd}]+/u', $options['delimiter'], $str);
	
	// Remove duplicate delimiters
	$str = preg_replace('/(' . preg_quote($options['delimiter'], '/') . '){2,}/', '$1', $str);
	
	// Truncate slug to max. characters
	$str = mb_substr($str, 0, ($options['limit'] ? $options['limit'] : mb_strlen($str, 'UTF-8')), 'UTF-8');
	
	// Remove delimiter from ends
	$str = trim($str, $options['delimiter']);
	
	return $options['lowercase'] ? mb_strtolower($str, 'UTF-8') : $str;
}
https://snipt.net/embed/6c4b352cb2f299cbf3c97177f4c393af/
/raw/6c4b352cb2f299cbf3c97177f4c393af/
6c4b352cb2f299cbf3c97177f4c393af
php
PHP
104
2019-08-24T00:13:40
True
False
False
Apr 25, 2013 at 09:30 AM
/api/public/snipt/59974/
friendly-url
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10"> 10</a> <a href="#L-11"> 11</a> <a href="#L-12"> 12</a> <a href="#L-13"> 13</a> <a href="#L-14"> 14</a> <a href="#L-15"> 15</a> <a href="#L-16"> 16</a> <a href="#L-17"> 17</a> <a href="#L-18"> 18</a> <a href="#L-19"> 19</a> <a href="#L-20"> 20</a> <a href="#L-21"> 21</a> <a href="#L-22"> 22</a> <a href="#L-23"> 23</a> <a href="#L-24"> 24</a> <a href="#L-25"> 25</a> <a href="#L-26"> 26</a> <a href="#L-27"> 27</a> <a href="#L-28"> 28</a> <a href="#L-29"> 29</a> <a href="#L-30"> 30</a> <a href="#L-31"> 31</a> <a href="#L-32"> 32</a> <a href="#L-33"> 33</a> <a href="#L-34"> 34</a> <a href="#L-35"> 35</a> <a href="#L-36"> 36</a> <a href="#L-37"> 37</a> <a href="#L-38"> 38</a> <a href="#L-39"> 39</a> <a href="#L-40"> 40</a> <a href="#L-41"> 41</a> <a href="#L-42"> 42</a> <a href="#L-43"> 43</a> <a href="#L-44"> 44</a> <a href="#L-45"> 45</a> <a href="#L-46"> 46</a> <a href="#L-47"> 47</a> <a href="#L-48"> 48</a> <a href="#L-49"> 49</a> <a href="#L-50"> 50</a> <a href="#L-51"> 51</a> <a href="#L-52"> 52</a> <a href="#L-53"> 53</a> <a href="#L-54"> 54</a> <a href="#L-55"> 55</a> <a href="#L-56"> 56</a> <a href="#L-57"> 57</a> <a href="#L-58"> 58</a> <a href="#L-59"> 59</a> <a href="#L-60"> 60</a> <a href="#L-61"> 61</a> <a href="#L-62"> 62</a> <a href="#L-63"> 63</a> <a href="#L-64"> 64</a> <a href="#L-65"> 65</a> <a href="#L-66"> 66</a> <a href="#L-67"> 67</a> <a href="#L-68"> 68</a> <a href="#L-69"> 69</a> <a href="#L-70"> 70</a> <a href="#L-71"> 71</a> <a href="#L-72"> 72</a> <a href="#L-73"> 73</a> <a href="#L-74"> 74</a> <a href="#L-75"> 75</a> <a href="#L-76"> 76</a> <a href="#L-77"> 77</a> <a href="#L-78"> 78</a> <a href="#L-79"> 79</a> <a href="#L-80"> 80</a> <a href="#L-81"> 81</a> <a href="#L-82"> 82</a> <a href="#L-83"> 83</a> <a href="#L-84"> 84</a> <a href="#L-85"> 85</a> <a href="#L-86"> 86</a> <a href="#L-87"> 87</a> <a href="#L-88"> 88</a> <a href="#L-89"> 89</a> <a href="#L-90"> 90</a> <a href="#L-91"> 91</a> <a href="#L-92"> 92</a> <a href="#L-93"> 93</a> <a href="#L-94"> 94</a> <a href="#L-95"> 95</a> <a href="#L-96"> 96</a> <a href="#L-97"> 97</a> <a href="#L-98"> 98</a> <a href="#L-99"> 99</a> <a href="#L-100">100</a> <a href="#L-101">101</a> <a href="#L-102">102</a> <a href="#L-103">103</a> <a href="#L-104">104</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">function url_slug($str, $options = array()) {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> // Make sure string is in UTF-8 and strip invalid UTF-8 characters</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> $str = mb_convert_encoding((string)$str, &#39;UTF-8&#39;, mb_list_encodings());</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> </span> </span><span id="L-5"><a name="L-5"></a><span class="x"> $defaults = array(</span> </span><span id="L-6"><a name="L-6"></a><span class="x"> &#39;delimiter&#39; =&gt; &#39;-&#39;,</span> </span><span id="L-7"><a name="L-7"></a><span class="x"> &#39;limit&#39; =&gt; null,</span> </span><span id="L-8"><a name="L-8"></a><span class="x"> &#39;lowercase&#39; =&gt; false,</span> </span><span id="L-9"><a name="L-9"></a><span class="x"> &#39;replacements&#39; =&gt; array(),</span> </span><span id="L-10"><a name="L-10"></a><span class="x"> &#39;transliterate&#39; =&gt; false,</span> </span><span id="L-11"><a name="L-11"></a><span class="x"> );</span> </span><span id="L-12"><a name="L-12"></a><span class="x"> </span> </span><span id="L-13"><a name="L-13"></a><span class="x"> // Merge options</span> </span><span id="L-14"><a name="L-14"></a><span class="x"> $options = array_merge($defaults, $options);</span> </span><span id="L-15"><a name="L-15"></a><span class="x"> </span> </span><span id="L-16"><a name="L-16"></a><span class="x"> $char_map = array(</span> </span><span id="L-17"><a name="L-17"></a><span class="x"> // Latin</span> </span><span id="L-18"><a name="L-18"></a><span class="x"> &#39;À&#39; =&gt; &#39;A&#39;, &#39;Á&#39; =&gt; &#39;A&#39;, &#39;Â&#39; =&gt; &#39;A&#39;, &#39;Ã&#39; =&gt; &#39;A&#39;, &#39;Ä&#39; =&gt; &#39;A&#39;, &#39;Å&#39; =&gt; &#39;A&#39;, &#39;Æ&#39; =&gt; &#39;AE&#39;, &#39;Ç&#39; =&gt; &#39;C&#39;, </span> </span><span id="L-19"><a name="L-19"></a><span class="x"> &#39;È&#39; =&gt; &#39;E&#39;, &#39;É&#39; =&gt; &#39;E&#39;, &#39;Ê&#39; =&gt; &#39;E&#39;, &#39;Ë&#39; =&gt; &#39;E&#39;, &#39;Ì&#39; =&gt; &#39;I&#39;, &#39;Í&#39; =&gt; &#39;I&#39;, &#39;Î&#39; =&gt; &#39;I&#39;, &#39;Ï&#39; =&gt; &#39;I&#39;, </span> </span><span id="L-20"><a name="L-20"></a><span class="x"> &#39;Ð&#39; =&gt; &#39;D&#39;, &#39;Ñ&#39; =&gt; &#39;N&#39;, &#39;Ò&#39; =&gt; &#39;O&#39;, &#39;Ó&#39; =&gt; &#39;O&#39;, &#39;Ô&#39; =&gt; &#39;O&#39;, &#39;Õ&#39; =&gt; &#39;O&#39;, &#39;Ö&#39; =&gt; &#39;O&#39;, &#39;Ő&#39; =&gt; &#39;O&#39;, </span> </span><span id="L-21"><a name="L-21"></a><span class="x"> &#39;Ø&#39; =&gt; &#39;O&#39;, &#39;Ù&#39; =&gt; &#39;U&#39;, &#39;Ú&#39; =&gt; &#39;U&#39;, &#39;Û&#39; =&gt; &#39;U&#39;, &#39;Ü&#39; =&gt; &#39;U&#39;, &#39;Ű&#39; =&gt; &#39;U&#39;, &#39;Ý&#39; =&gt; &#39;Y&#39;, &#39;Þ&#39; =&gt; &#39;TH&#39;, </span> </span><span id="L-22"><a name="L-22"></a><span class="x"> &#39;ß&#39; =&gt; &#39;ss&#39;, </span> </span><span id="L-23"><a name="L-23"></a><span class="x"> &#39;à&#39; =&gt; &#39;a&#39;, &#39;á&#39; =&gt; &#39;a&#39;, &#39;â&#39; =&gt; &#39;a&#39;, &#39;ã&#39; =&gt; &#39;a&#39;, &#39;ä&#39; =&gt; &#39;a&#39;, &#39;å&#39; =&gt; &#39;a&#39;, &#39;æ&#39; =&gt; &#39;ae&#39;, &#39;ç&#39; =&gt; &#39;c&#39;, </span> </span><span id="L-24"><a name="L-24"></a><span class="x"> &#39;è&#39; =&gt; &#39;e&#39;, &#39;é&#39; =&gt; &#39;e&#39;, &#39;ê&#39; =&gt; &#39;e&#39;, &#39;ë&#39; =&gt; &#39;e&#39;, &#39;ì&#39; =&gt; &#39;i&#39;, &#39;í&#39; =&gt; &#39;i&#39;, &#39;î&#39; =&gt; &#39;i&#39;, &#39;ï&#39; =&gt; &#39;i&#39;, </span> </span><span id="L-25"><a name="L-25"></a><span class="x"> &#39;ð&#39; =&gt; &#39;d&#39;, &#39;ñ&#39; =&gt; &#39;n&#39;, &#39;ò&#39; =&gt; &#39;o&#39;, &#39;ó&#39; =&gt; &#39;o&#39;, &#39;ô&#39; =&gt; &#39;o&#39;, &#39;õ&#39; =&gt; &#39;o&#39;, &#39;ö&#39; =&gt; &#39;o&#39;, &#39;ő&#39; =&gt; &#39;o&#39;, </span> </span><span id="L-26"><a name="L-26"></a><span class="x"> &#39;ø&#39; =&gt; &#39;o&#39;, &#39;ù&#39; =&gt; &#39;u&#39;, &#39;ú&#39; =&gt; &#39;u&#39;, &#39;û&#39; =&gt; &#39;u&#39;, &#39;ü&#39; =&gt; &#39;u&#39;, &#39;ű&#39; =&gt; &#39;u&#39;, &#39;ý&#39; =&gt; &#39;y&#39;, &#39;þ&#39; =&gt; &#39;th&#39;, </span> </span><span id="L-27"><a name="L-27"></a><span class="x"> &#39;ÿ&#39; =&gt; &#39;y&#39;,</span> </span><span id="L-28"><a name="L-28"></a><span class="x"> </span> </span><span id="L-29"><a name="L-29"></a><span class="x"> // Latin symbols</span> </span><span id="L-30"><a name="L-30"></a><span class="x"> &#39;©&#39; =&gt; &#39;(c)&#39;,</span> </span><span id="L-31"><a name="L-31"></a><span class="x"> </span> </span><span id="L-32"><a name="L-32"></a><span class="x"> // Greek</span> </span><span id="L-33"><a name="L-33"></a><span class="x"> &#39;Α&#39; =&gt; &#39;A&#39;, &#39;Β&#39; =&gt; &#39;B&#39;, &#39;Γ&#39; =&gt; &#39;G&#39;, &#39;Δ&#39; =&gt; &#39;D&#39;, &#39;Ε&#39; =&gt; &#39;E&#39;, &#39;Ζ&#39; =&gt; &#39;Z&#39;, &#39;Η&#39; =&gt; &#39;H&#39;, &#39;Θ&#39; =&gt; &#39;8&#39;,</span> </span><span id="L-34"><a name="L-34"></a><span class="x"> &#39;Ι&#39; =&gt; &#39;I&#39;, &#39;Κ&#39; =&gt; &#39;K&#39;, &#39;Λ&#39; =&gt; &#39;L&#39;, &#39;Μ&#39; =&gt; &#39;M&#39;, &#39;Ν&#39; =&gt; &#39;N&#39;, &#39;Ξ&#39; =&gt; &#39;3&#39;, &#39;Ο&#39; =&gt; &#39;O&#39;, &#39;Π&#39; =&gt; &#39;P&#39;,</span> </span><span id="L-35"><a name="L-35"></a><span class="x"> &#39;Ρ&#39; =&gt; &#39;R&#39;, &#39;Σ&#39; =&gt; &#39;S&#39;, &#39;Τ&#39; =&gt; &#39;T&#39;, &#39;Υ&#39; =&gt; &#39;Y&#39;, &#39;Φ&#39; =&gt; &#39;F&#39;, &#39;Χ&#39; =&gt; &#39;X&#39;, &#39;Ψ&#39; =&gt; &#39;PS&#39;, &#39;Ω&#39; =&gt; &#39;W&#39;,</span> </span><span id="L-36"><a name="L-36"></a><span class="x"> &#39;Ά&#39; =&gt; &#39;A&#39;, &#39;Έ&#39; =&gt; &#39;E&#39;, &#39;Ί&#39; =&gt; &#39;I&#39;, &#39;Ό&#39; =&gt; &#39;O&#39;, &#39;Ύ&#39; =&gt; &#39;Y&#39;, &#39;Ή&#39; =&gt; &#39;H&#39;, &#39;Ώ&#39; =&gt; &#39;W&#39;, &#39;Ϊ&#39; =&gt; &#39;I&#39;,</span> </span><span id="L-37"><a name="L-37"></a><span class="x"> &#39;Ϋ&#39; =&gt; &#39;Y&#39;,</span> </span><span id="L-38"><a name="L-38"></a><span class="x"> &#39;α&#39; =&gt; &#39;a&#39;, &#39;β&#39; =&gt; &#39;b&#39;, &#39;γ&#39; =&gt; &#39;g&#39;, &#39;δ&#39; =&gt; &#39;d&#39;, &#39;ε&#39; =&gt; &#39;e&#39;, &#39;ζ&#39; =&gt; &#39;z&#39;, &#39;η&#39; =&gt; &#39;h&#39;, &#39;θ&#39; =&gt; &#39;8&#39;,</span> </span><span id="L-39"><a name="L-39"></a><span class="x"> &#39;ι&#39; =&gt; &#39;i&#39;, &#39;κ&#39; =&gt; &#39;k&#39;, &#39;λ&#39; =&gt; &#39;l&#39;, &#39;μ&#39; =&gt; &#39;m&#39;, &#39;ν&#39; =&gt; &#39;n&#39;, &#39;ξ&#39; =&gt; &#39;3&#39;, &#39;ο&#39; =&gt; &#39;o&#39;, &#39;π&#39; =&gt; &#39;p&#39;,</span> </span><span id="L-40"><a name="L-40"></a><span class="x"> &#39;ρ&#39; =&gt; &#39;r&#39;, &#39;σ&#39; =&gt; &#39;s&#39;, &#39;τ&#39; =&gt; &#39;t&#39;, &#39;υ&#39; =&gt; &#39;y&#39;, &#39;φ&#39; =&gt; &#39;f&#39;, &#39;χ&#39; =&gt; &#39;x&#39;, &#39;ψ&#39; =&gt; &#39;ps&#39;, &#39;ω&#39; =&gt; &#39;w&#39;,</span> </span><span id="L-41"><a name="L-41"></a><span class="x"> &#39;ά&#39; =&gt; &#39;a&#39;, &#39;έ&#39; =&gt; &#39;e&#39;, &#39;ί&#39; =&gt; &#39;i&#39;, &#39;ό&#39; =&gt; &#39;o&#39;, &#39;ύ&#39; =&gt; &#39;y&#39;, &#39;ή&#39; =&gt; &#39;h&#39;, &#39;ώ&#39; =&gt; &#39;w&#39;, &#39;ς&#39; =&gt; &#39;s&#39;,</span> </span><span id="L-42"><a name="L-42"></a><span class="x"> &#39;ϊ&#39; =&gt; &#39;i&#39;, &#39;ΰ&#39; =&gt; &#39;y&#39;, &#39;ϋ&#39; =&gt; &#39;y&#39;, &#39;ΐ&#39; =&gt; &#39;i&#39;,</span> </span><span id="L-43"><a name="L-43"></a><span class="x"> </span> </span><span id="L-44"><a name="L-44"></a><span class="x"> // Turkish</span> </span><span id="L-45"><a name="L-45"></a><span class="x"> &#39;Ş&#39; =&gt; &#39;S&#39;, &#39;İ&#39; =&gt; &#39;I&#39;, &#39;Ç&#39; =&gt; &#39;C&#39;, &#39;Ü&#39; =&gt; &#39;U&#39;, &#39;Ö&#39; =&gt; &#39;O&#39;, &#39;Ğ&#39; =&gt; &#39;G&#39;,</span> </span><span id="L-46"><a name="L-46"></a><span class="x"> &#39;ş&#39; =&gt; &#39;s&#39;, &#39;ı&#39; =&gt; &#39;i&#39;, &#39;ç&#39; =&gt; &#39;c&#39;, &#39;ü&#39; =&gt; &#39;u&#39;, &#39;ö&#39; =&gt; &#39;o&#39;, &#39;ğ&#39; =&gt; &#39;g&#39;, </span> </span><span id="L-47"><a name="L-47"></a><span class="x"> </span> </span><span id="L-48"><a name="L-48"></a><span class="x"> // Russian</span> </span><span id="L-49"><a name="L-49"></a><span class="x"> &#39;А&#39; =&gt; &#39;A&#39;, &#39;Б&#39; =&gt; &#39;B&#39;, &#39;В&#39; =&gt; &#39;V&#39;, &#39;Г&#39; =&gt; &#39;G&#39;, &#39;Д&#39; =&gt; &#39;D&#39;, &#39;Е&#39; =&gt; &#39;E&#39;, &#39;Ё&#39; =&gt; &#39;Yo&#39;, &#39;Ж&#39; =&gt; &#39;Zh&#39;,</span> </span><span id="L-50"><a name="L-50"></a><span class="x"> &#39;З&#39; =&gt; &#39;Z&#39;, &#39;И&#39; =&gt; &#39;I&#39;, &#39;Й&#39; =&gt; &#39;J&#39;, &#39;К&#39; =&gt; &#39;K&#39;, &#39;Л&#39; =&gt; &#39;L&#39;, &#39;М&#39; =&gt; &#39;M&#39;, &#39;Н&#39; =&gt; &#39;N&#39;, &#39;О&#39; =&gt; &#39;O&#39;,</span> </span><span id="L-51"><a name="L-51"></a><span class="x"> &#39;П&#39; =&gt; &#39;P&#39;, &#39;Р&#39; =&gt; &#39;R&#39;, &#39;С&#39; =&gt; &#39;S&#39;, &#39;Т&#39; =&gt; &#39;T&#39;, &#39;У&#39; =&gt; &#39;U&#39;, &#39;Ф&#39; =&gt; &#39;F&#39;, &#39;Х&#39; =&gt; &#39;H&#39;, &#39;Ц&#39; =&gt; &#39;C&#39;,</span> </span><span id="L-52"><a name="L-52"></a><span class="x"> &#39;Ч&#39; =&gt; &#39;Ch&#39;, &#39;Ш&#39; =&gt; &#39;Sh&#39;, &#39;Щ&#39; =&gt; &#39;Sh&#39;, &#39;Ъ&#39; =&gt; &#39;&#39;, &#39;Ы&#39; =&gt; &#39;Y&#39;, &#39;Ь&#39; =&gt; &#39;&#39;, &#39;Э&#39; =&gt; &#39;E&#39;, &#39;Ю&#39; =&gt; &#39;Yu&#39;,</span> </span><span id="L-53"><a name="L-53"></a><span class="x"> &#39;Я&#39; =&gt; &#39;Ya&#39;,</span> </span><span id="L-54"><a name="L-54"></a><span class="x"> &#39;а&#39; =&gt; &#39;a&#39;, &#39;б&#39; =&gt; &#39;b&#39;, &#39;в&#39; =&gt; &#39;v&#39;, &#39;г&#39; =&gt; &#39;g&#39;, &#39;д&#39; =&gt; &#39;d&#39;, &#39;е&#39; =&gt; &#39;e&#39;, &#39;ё&#39; =&gt; &#39;yo&#39;, &#39;ж&#39; =&gt; &#39;zh&#39;,</span> </span><span id="L-55"><a name="L-55"></a><span class="x"> &#39;з&#39; =&gt; &#39;z&#39;, &#39;и&#39; =&gt; &#39;i&#39;, &#39;й&#39; =&gt; &#39;j&#39;, &#39;к&#39; =&gt; &#39;k&#39;, &#39;л&#39; =&gt; &#39;l&#39;, &#39;м&#39; =&gt; &#39;m&#39;, &#39;н&#39; =&gt; &#39;n&#39;, &#39;о&#39; =&gt; &#39;o&#39;,</span> </span><span id="L-56"><a name="L-56"></a><span class="x"> &#39;п&#39; =&gt; &#39;p&#39;, &#39;р&#39; =&gt; &#39;r&#39;, &#39;с&#39; =&gt; &#39;s&#39;, &#39;т&#39; =&gt; &#39;t&#39;, &#39;у&#39; =&gt; &#39;u&#39;, &#39;ф&#39; =&gt; &#39;f&#39;, &#39;х&#39; =&gt; &#39;h&#39;, &#39;ц&#39; =&gt; &#39;c&#39;,</span> </span><span id="L-57"><a name="L-57"></a><span class="x"> &#39;ч&#39; =&gt; &#39;ch&#39;, &#39;ш&#39; =&gt; &#39;sh&#39;, &#39;щ&#39; =&gt; &#39;sh&#39;, &#39;ъ&#39; =&gt; &#39;&#39;, &#39;ы&#39; =&gt; &#39;y&#39;, &#39;ь&#39; =&gt; &#39;&#39;, &#39;э&#39; =&gt; &#39;e&#39;, &#39;ю&#39; =&gt; &#39;yu&#39;,</span> </span><span id="L-58"><a name="L-58"></a><span class="x"> &#39;я&#39; =&gt; &#39;ya&#39;,</span> </span><span id="L-59"><a name="L-59"></a><span class="x"> </span> </span><span id="L-60"><a name="L-60"></a><span class="x"> // Ukrainian</span> </span><span id="L-61"><a name="L-61"></a><span class="x"> &#39;Є&#39; =&gt; &#39;Ye&#39;, &#39;І&#39; =&gt; &#39;I&#39;, &#39;Ї&#39; =&gt; &#39;Yi&#39;, &#39;Ґ&#39; =&gt; &#39;G&#39;,</span> </span><span id="L-62"><a name="L-62"></a><span class="x"> &#39;є&#39; =&gt; &#39;ye&#39;, &#39;і&#39; =&gt; &#39;i&#39;, &#39;ї&#39; =&gt; &#39;yi&#39;, &#39;ґ&#39; =&gt; &#39;g&#39;,</span> </span><span id="L-63"><a name="L-63"></a><span class="x"> </span> </span><span id="L-64"><a name="L-64"></a><span class="x"> // Czech</span> </span><span id="L-65"><a name="L-65"></a><span class="x"> &#39;Č&#39; =&gt; &#39;C&#39;, &#39;Ď&#39; =&gt; &#39;D&#39;, &#39;Ě&#39; =&gt; &#39;E&#39;, &#39;Ň&#39; =&gt; &#39;N&#39;, &#39;Ř&#39; =&gt; &#39;R&#39;, &#39;Š&#39; =&gt; &#39;S&#39;, &#39;Ť&#39; =&gt; &#39;T&#39;, &#39;Ů&#39; =&gt; &#39;U&#39;, </span> </span><span id="L-66"><a name="L-66"></a><span class="x"> &#39;Ž&#39; =&gt; &#39;Z&#39;, </span> </span><span id="L-67"><a name="L-67"></a><span class="x"> &#39;č&#39; =&gt; &#39;c&#39;, &#39;ď&#39; =&gt; &#39;d&#39;, &#39;ě&#39; =&gt; &#39;e&#39;, &#39;ň&#39; =&gt; &#39;n&#39;, &#39;ř&#39; =&gt; &#39;r&#39;, &#39;š&#39; =&gt; &#39;s&#39;, &#39;ť&#39; =&gt; &#39;t&#39;, &#39;ů&#39; =&gt; &#39;u&#39;,</span> </span><span id="L-68"><a name="L-68"></a><span class="x"> &#39;ž&#39; =&gt; &#39;z&#39;, </span> </span><span id="L-69"><a name="L-69"></a><span class="x"> </span> </span><span id="L-70"><a name="L-70"></a><span class="x"> // Polish</span> </span><span id="L-71"><a name="L-71"></a><span class="x"> &#39;Ą&#39; =&gt; &#39;A&#39;, &#39;Ć&#39; =&gt; &#39;C&#39;, &#39;Ę&#39; =&gt; &#39;e&#39;, &#39;Ł&#39; =&gt; &#39;L&#39;, &#39;Ń&#39; =&gt; &#39;N&#39;, &#39;Ó&#39; =&gt; &#39;o&#39;, &#39;Ś&#39; =&gt; &#39;S&#39;, &#39;Ź&#39; =&gt; &#39;Z&#39;, </span> </span><span id="L-72"><a name="L-72"></a><span class="x"> &#39;Ż&#39; =&gt; &#39;Z&#39;, </span> </span><span id="L-73"><a name="L-73"></a><span class="x"> &#39;ą&#39; =&gt; &#39;a&#39;, &#39;ć&#39; =&gt; &#39;c&#39;, &#39;ę&#39; =&gt; &#39;e&#39;, &#39;ł&#39; =&gt; &#39;l&#39;, &#39;ń&#39; =&gt; &#39;n&#39;, &#39;ó&#39; =&gt; &#39;o&#39;, &#39;ś&#39; =&gt; &#39;s&#39;, &#39;ź&#39; =&gt; &#39;z&#39;,</span> </span><span id="L-74"><a name="L-74"></a><span class="x"> &#39;ż&#39; =&gt; &#39;z&#39;,</span> </span><span id="L-75"><a name="L-75"></a><span class="x"> </span> </span><span id="L-76"><a name="L-76"></a><span class="x"> // Latvian</span> </span><span id="L-77"><a name="L-77"></a><span class="x"> &#39;Ā&#39; =&gt; &#39;A&#39;, &#39;Č&#39; =&gt; &#39;C&#39;, &#39;Ē&#39; =&gt; &#39;E&#39;, &#39;Ģ&#39; =&gt; &#39;G&#39;, &#39;Ī&#39; =&gt; &#39;i&#39;, &#39;Ķ&#39; =&gt; &#39;k&#39;, &#39;Ļ&#39; =&gt; &#39;L&#39;, &#39;Ņ&#39; =&gt; &#39;N&#39;, </span> </span><span id="L-78"><a name="L-78"></a><span class="x"> &#39;Š&#39; =&gt; &#39;S&#39;, &#39;Ū&#39; =&gt; &#39;u&#39;, &#39;Ž&#39; =&gt; &#39;Z&#39;,</span> </span><span id="L-79"><a name="L-79"></a><span class="x"> &#39;ā&#39; =&gt; &#39;a&#39;, &#39;č&#39; =&gt; &#39;c&#39;, &#39;ē&#39; =&gt; &#39;e&#39;, &#39;ģ&#39; =&gt; &#39;g&#39;, &#39;ī&#39; =&gt; &#39;i&#39;, &#39;ķ&#39; =&gt; &#39;k&#39;, &#39;ļ&#39; =&gt; &#39;l&#39;, &#39;ņ&#39; =&gt; &#39;n&#39;,</span> </span><span id="L-80"><a name="L-80"></a><span class="x"> &#39;š&#39; =&gt; &#39;s&#39;, &#39;ū&#39; =&gt; &#39;u&#39;, &#39;ž&#39; =&gt; &#39;z&#39;</span> </span><span id="L-81"><a name="L-81"></a><span class="x"> );</span> </span><span id="L-82"><a name="L-82"></a><span class="x"> </span> </span><span id="L-83"><a name="L-83"></a><span class="x"> // Make custom replacements</span> </span><span id="L-84"><a name="L-84"></a><span class="x"> $str = preg_replace(array_keys($options[&#39;replacements&#39;]), $options[&#39;replacements&#39;], $str);</span> </span><span id="L-85"><a name="L-85"></a><span class="x"> </span> </span><span id="L-86"><a name="L-86"></a><span class="x"> // Transliterate characters to ASCII</span> </span><span id="L-87"><a name="L-87"></a><span class="x"> if ($options[&#39;transliterate&#39;]) {</span> </span><span id="L-88"><a name="L-88"></a><span class="x"> $str = str_replace(array_keys($char_map), $char_map, $str);</span> </span><span id="L-89"><a name="L-89"></a><span class="x"> }</span> </span><span id="L-90"><a name="L-90"></a><span class="x"> </span> </span><span id="L-91"><a name="L-91"></a><span class="x"> // Replace non-alphanumeric characters with our delimiter</span> </span><span id="L-92"><a name="L-92"></a><span class="x"> $str = preg_replace(&#39;/[^\p{L}\p{Nd}]+/u&#39;, $options[&#39;delimiter&#39;], $str);</span> </span><span id="L-93"><a name="L-93"></a><span class="x"> </span> </span><span id="L-94"><a name="L-94"></a><span class="x"> // Remove duplicate delimiters</span> </span><span id="L-95"><a name="L-95"></a><span class="x"> $str = preg_replace(&#39;/(&#39; . preg_quote($options[&#39;delimiter&#39;], &#39;/&#39;) . &#39;){2,}/&#39;, &#39;$1&#39;, $str);</span> </span><span id="L-96"><a name="L-96"></a><span class="x"> </span> </span><span id="L-97"><a name="L-97"></a><span class="x"> // Truncate slug to max. characters</span> </span><span id="L-98"><a name="L-98"></a><span class="x"> $str = mb_substr($str, 0, ($options[&#39;limit&#39;] ? $options[&#39;limit&#39;] : mb_strlen($str, &#39;UTF-8&#39;)), &#39;UTF-8&#39;);</span> </span><span id="L-99"><a name="L-99"></a><span class="x"> </span> </span><span id="L-100"><a name="L-100"></a><span class="x"> // Remove delimiter from ends</span> </span><span id="L-101"><a name="L-101"></a><span class="x"> $str = trim($str, $options[&#39;delimiter&#39;]);</span> </span><span id="L-102"><a name="L-102"></a><span class="x"> </span> </span><span id="L-103"><a name="L-103"></a><span class="x"> return $options[&#39;lowercase&#39;] ? mb_strtolower($str, &#39;UTF-8&#39;) : $str;</span> </span><span id="L-104"><a name="L-104"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
"Friendly URL", PHP