首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel 4西里尔文弹头

Laravel 4西里尔文弹头
EN

Stack Overflow用户
提问于 2013-04-24 22:19:58
回答 2查看 1.6K关注 0票数 2

目前在L4中,你不能从西里尔字符串中获取slug。在L3中,有一个用于此的ascii数组。我可以在哪里以及如何添加这个数组/功能,以便从西里尔字符串创建一个slug?

编辑

https://github.com/cocur/slugify是一个很好的选择,但我决定在L4中使用来自L3方法和ascii数组的自定义插件库。现在,我在L4中可以像在L3中一样使用Slug maker。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-24 22:33:25

你可以通过composer安装这个库(https://github.com/cocur/slugify)并使用。

它非常容易安装和使用。

票数 2
EN

Stack Overflow用户

发布于 2015-03-23 03:40:31

我在使用阿拉伯语时遇到过这个问题,所以我做了以下函数,为我解决了这个问题。

代码语言:javascript
复制
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;
}

这个函数只解决阿拉伯语言的问题,如果你想解决西里尔语或任何其他语言的问题,你需要在这些ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى现有的阿拉伯字符旁边添加西里尔字符(或其他语言的字符)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16194469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档