I am using this to create username based on name. Name needs to be utf8 but username does not. How could I convert utf8 to non utf8?
public static function createUsername ($name, $count = 0) {
$username = implode('.', explode(' ', strtolower($name)));
if ($count > 0) {
$username = $username . $count;
}
if (count(self::where('username', $username)->get()) > 0) {
self::createUsername($name, $count++);
}
return $username;
}
Laravel provides a function for converting utf-8 strings into ASCCI.
Str::ascii($string)
I'm not entirely sure why you would want to do this as the performance gain is likely not all too great. See Does using ASCII/Latin Charset speed up the database?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.