Since you seem to want all sequences of non-alphanumeric characters being replaced by a single hyphen, you can use this:
$str = preg_replace('/[^a-zA-Z0-9]+/', '-', $str);
But this can result in leading or trailing hyphens that can be removed with trim
:
$str = trim($str, '-');
And to convert the result into lowercase, use strtolower
:
$str = strtolower($str);
So all together:
$str = strtolower($str);
$str = trim($str, '-');
$str = preg_replace('/[^a-z0-9]+/', '-', $str);
Or in a compact one-liner:
$str = strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/', '-', $str), '-'));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…