我使用以下方法将字符串中的特殊字符转换为破折号,但保留字母数字字符:
return preg_replace("![^a-z0-9]+!i", "-", $str);
然而,在某些情况下,我有这些字符串:
$str = "Hello there chubby!";
这将导致:
Hello-there-chubby-
单词末尾的破折号让我想到了一种解决方法,可以去除它。
我使用以下方法将字符串中的特殊字符转换为破折号,但保留字母数字字符:
return preg_replace("![^a-z0-9]+!i", "-", $str);
$str = "Hello there chubby!";
Hello-there-chubby-
单词末尾的破折号让我想到了一种解决方法,可以去除它。