目前在L4你不能從西里爾字符串得到slu slu。在L3中有一個ascii數組。在哪裏以及如何添加這個數組/能力來從西里爾字符串創建一個slu??Laravel 4西里爾slu 012
EDIT
庫https://github.com/cocur/slugify是一個好的選擇,但我決定在L4使用來自L3的方法和ASCII陣列定製彈頭庫。現在我已經在L4工作,就像L3一樣。
目前在L4你不能從西里爾字符串得到slu slu。在L3中有一個ascii數組。在哪裏以及如何添加這個數組/能力來從西里爾字符串創建一個slu??Laravel 4西里爾slu 012
EDIT
庫https://github.com/cocur/slugify是一個好的選擇,但我決定在L4使用來自L3的方法和ASCII陣列定製彈頭庫。現在我已經在L4工作,就像L3一樣。
您可以通過作曲家安裝此庫(https://github.com/cocur/slugify)並使用。
這是超級簡單的安裝和使用。
我在使用阿拉伯語的時候遇到了這個問題,所以我做了下面的函數來解決這個問題。
function make_slug($string = null, $separator = "-") {
if (is_null($string)) {
return "";
}
// Remove spaces from the beginning and from the end of the string
$string = trim($string);
// Lower case everything
// using mb_strtolower() function is important for non-Latin UTF-8 string | more info: http://goo.gl/QL2tzK
$string = mb_strtolower($string, "UTF-8");;
// Make alphanumeric (removes all other characters)
// this makes the string safe especially when used as a part of a URL
// this keeps latin characters and arabic charactrs as well
$string = preg_replace("/[^a-z0-9_\s-ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى]/u", "", $string);
// Remove multiple dashes or whitespaces
$string = preg_replace("/[\s-]+/", " ", $string);
// Convert whitespaces and underscore to the given separator
$string = preg_replace("/[\s_]/", $separator, $string);
return $string;
}
此功能解決了這個問題只爲阿拉伯語,如果你想解決西里爾或任何其他語言的問題,你需要添加西裏爾字母(或其他語言的字符)的旁邊,而不是這些或現有阿拉伯字符。
請解釋如何安裝它? 我一點也不覺得簡單。 – Paul 2015-02-14 19:55:47
只需添加到您的composer.json文件,作曲家更新並按照存儲庫說明使用。 – 2015-02-16 22:44:51
我認爲最好還爲那些不使用Composer的用戶提供安裝說明。 我無法理解它,所以我放棄了它,並使用了更簡單的另一段代碼。 – Paul 2015-02-17 23:28:08