php正则表达式:只保留语言(各个国家语言,譬如中文,英文,德文),数字,空格,此表达式用来根据产品名称生成URL
$pattern = "/([^0-9\p{L}\s*]+)/u";
$handle = preg_replace($pattern,'', $handle);
$handle = preg_replace('!\s+!', ' ', $handle);
$handle = str_replace(' ','-', $handle);
$handle = trim($handle);
$handle = $handle ?: StringHelper::random(10);
StringHelper::random(10)
: 函数代表生成一个10位的随机数
如果包含多个空格,多个空格先处理成一个空格(preg_replace('!\s+!', ' ', $handle)
),然后, 空格替换成连接符($handle = str_replace(' ','-', $handle);
)