{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":".github","path":".github","contentType":"directory"},{"name":"scripts","path":"scripts","contentType":"directory"},{"name":"tests","path":"tests","contentType":"directory"},{"name":".editorconfig","path":".editorconfig","contentType":"file"},{"name":".gitattributes","path":".gitattributes","contentType":"file"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":"INSTALL","path":"INSTALL","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"URLify.php","path":"URLify.php","contentType":"file"},{"name":"composer.json","path":"composer.json","contentType":"file"},{"name":"phpcs.php_cs","path":"phpcs.php_cs","contentType":"file"},{"name":"phpstan.neon","path":"phpstan.neon","contentType":"file"},{"name":"phpunit.xml","path":"phpunit.xml","contentType":"file"}],"totalCount":14}},"fileTreeProcessingTime":6.361573,"foldersToFetch":[],"repo":{"id":4197217,"defaultBranch":"master","name":"urlify","ownerLogin":"jbroadway","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2012-05-01T22:28:56.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/87886?v=4","public":true,"private":false,"isOrgOwned":false},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1655312582.178863","canEdit":false,"refType":"branch","currentOid":"4fc01dc06c341f45c30ca5881d429a315daab9a3"},"path":"URLify.php","currentUser":null,"blob":{"rawLines":["An array of things that should replaced by the separator.
"," * @param bool $mergeKeep the previous (default) array-to-separator array.
"," *"," * @return void"," *"," * @psalm-param string[] $array"," */"," public static function add_array_to_separator(array $array, bool $merge = true)"," {"," if ($merge === true) {"," self::$arrayToSeparator = \\array_unique("," \\array_merge("," self::$arrayToSeparator,"," $array"," )"," );"," } else {"," self::$arrayToSeparator = $array;"," }"," }",""," /**"," * Add new characters to the list. `$map` should be a hash."," *"," * @param array $map"," * @param string|null $language"," *"," * @return void"," *"," * @psalm-param arrayThe input string.
"," * @param string $languageYour primary language.
"," * @param string $unknownCharacter use if character unknown. (default is ?).
"," *"," * @return string"," */"," public static function downcode("," string $string,"," string $language = 'en',"," string $unknown = ''"," ): string {"," $string = self::expandString($string, $language);",""," foreach (self::$maps as $mapsInner) {"," foreach ($mapsInner as $orig => $replace) {"," $string = \\str_replace($orig, $replace, $string);"," }"," }",""," $string = \\voku\\helper\\ASCII::to_ascii("," $string,"," $language,"," false,"," true"," );",""," return \\voku\\helper\\ASCII::to_transliterate("," $string,"," $unknown,"," false"," );"," }"," "," /**"," * Convert a String to URL slug. Wraps filter() with a simpler"," * set of defaults for typical usage in generating blog post slugs."," *"," * @param string $stringThe text you want to convert.
"," * @param int $maxLengthMax. length of the output string, set to \"0\" (zero) to"," * disable it
"," * @param string $separatorDefine a new separator for the words.
"," * @param string $languageThe language you want to convert to.
"," */"," public static function slug("," \tstring $string,"," \tint $maxLength = 200,"," \tstring $separator = '-',"," \tstring $language = 'en'"," ): string {"," \treturn self::filter ($string, $maxLength, $language, false, false, true, $separator);"," }",""," /**"," * Convert a String to URL."," *"," * e.g.: \"PettyThe text you want to convert.
"," * @param int $maxLengthMax. length of the output string, set to \"0\" (zero) to"," * disable it
"," * @param string $languageThe language you want to convert to.
"," * @param bool $fileName"," * Keep the \".\" from the extension e.g.: \"imaäe.jpg\" =>"," * \"image.jpg\""," *
"," * @param bool $removeWords"," * Remove some \"words\" from the string.
"," * Info: Set extra words via remove_words()."," *
Use strtolower() at the end.
"," * @param bool|string $separatorDefine a new separator for the words.
"," *"," * @return string"," */"," public static function filter("," string $string,"," int $maxLength = 200,"," string $language = 'en',"," bool $fileName = false,"," bool $removeWords = false,"," bool $strToLower = true,"," $separator = '-'"," ): string {"," if ($string === '') {"," return '';"," }",""," // fallback"," if ($language === '') {"," $language = 'en';"," }",""," // separator-fallback"," if ($separator === false) {"," $separator = '_';"," }"," if ($separator === true || $separator === '') {"," $separator = '-';"," }",""," // escaped separator"," $separatorEscaped = \\preg_quote($separator, '/');",""," // use defaults, if there are no values"," if (self::$arrayToSeparator === []) {"," self::reset_array_to_separator();"," }",""," // remove apostrophes which are not used as quotes around a string"," if (\\strpos($string, \"'\") !== false) {"," $stringTmp = \\preg_replace(\"/(\\w)'(\\w)/u\", '${1}${2}', $string);"," if ($stringTmp !== null) {"," $string = (string) $stringTmp;"," }"," }",""," // replace with $separator"," $string = (string) \\preg_replace("," self::$arrayToSeparator,"," $separator,"," $string"," );",""," // remove all other html-tags"," if ("," \\strpos($string, '<') !== false"," ||"," \\strpos($string, '>') !== false"," ) {"," $string = \\strip_tags($string);"," }",""," // use special language replacer"," $string = self::downcode($string, $language);",""," // replace with $separator, again"," $string = (string) \\preg_replace("," self::$arrayToSeparator,"," $separator,"," $string"," );",""," // remove all these words from the string before urlifying"," $removeWordsSearch = '//';"," if ($removeWords === true) {"," $removeList = self::get_remove_list($language);"," if ($removeList !== []) {"," $removeWordsSearch = '/\\b(?:' . \\implode('|', $removeList) . ')\\b/ui';"," }"," }",""," // keep the \".\" from e.g.: a file-extension?"," if ($fileName) {"," $removePatternAddOn = '.';"," } else {"," $removePatternAddOn = '';"," }",""," $string = (string) \\preg_replace("," ["," // 1) remove un-needed chars"," '/[^' . $separatorEscaped . $removePatternAddOn . '\\-a-zA-Z0-9\\s]/u',"," // 2) convert spaces to $separator"," '/[\\s]+/u',"," // 3) remove some extras words"," $removeWordsSearch,"," // 4) remove double $separator's"," '/[' . ($separatorEscaped ?: ' ') . ']+/u',"," // 5) remove $separator at the end"," '/[' . ($separatorEscaped ?: ' ') . ']+$/u',"," ],"," ["," '',"," $separator,"," '',"," $separator,"," '',"," ],"," $string"," );",""," // \"substr\" only if \"$length\" is set"," if ("," $maxLength"," &&"," $maxLength > 0"," &&"," \\strlen($string) > $maxLength"," ) {"," $string = (string) \\substr(\\trim($string, $separator), 0, $maxLength);"," }",""," // convert to lowercase"," if ($strToLower === true) {"," $string = \\strtolower($string);"," }",""," // trim \"$separator\" from beginning and end of the string"," return \\trim($string, $separator);"," }",""," /**"," * Append words to the remove list. Accepts either single words or an array of words."," *"," * @param string|string[] $words"," * @param string $language"," * @param bool $mergeKeep the previous (default) remove-words array.
"," *"," * @return void"," */"," public static function remove_words($words, string $language = 'en', bool $merge = true)"," {"," if (\\is_array($words) === false) {"," $words = [$words];"," }",""," foreach ($words as $removeWordKey => $removeWord) {"," $words[$removeWordKey] = \\preg_quote($removeWord, '/');"," }",""," if ($merge === true) {"," self::$remove_list[$language] = \\array_unique("," \\array_merge("," self::get_remove_list($language),"," $words"," )"," );"," } else {"," self::$remove_list[$language] = $words;"," }"," }",""," /**"," * Reset the internal \"self::$arrayToSeparator\" to the default values."," *"," * @return void"," */"," public static function reset_array_to_separator()"," {"," self::$arrayToSeparator = ["," '/"|&|<|>|–|—/i', // \", &, <, >, –, —"," '/⁻|-|—|_|\"|`|´|\\'/',"," \"#/\\r\\n|\\r|\\n|