php slug,PHP使用str_slug而不更改大写字母

想要使用str_slug将文本更改为Slug.它适用于不同情况,但我希望它在不更改UpperCases的情况下工作,即

例如:您好—世界=>你好,世界

有没有办法得到我想要的?

解决方法:

如关于laracasts.com的问题所述,您可以创建自己的helper函数版本,从而省去了mb_strtolower():

public static function slug($title, $separator = '-', $language = 'en')

{

$title = static::ascii($title, $language);

// Convert all dashes/underscores into separator

$flip = $separator == '-' ? '_' : '-';

$title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);

// Replace @ with the word 'at'

$title = str_replace('@', $separator.'at'.$separator, $title);

// Remove all characters that are not the separator, letters, numbers, or whitespace.

// With lower case: $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title));

$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', $title);

// Replace all separator characters and whitespace by a single separator

$title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);

return trim($title, $separator);

}

标签:laravel,string,php

来源: https://codeday.me/bug/20191025/1928369.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值