- preg_replace: documentation ( source)
- strtolower: documentation ( source)
<?php
$regex1 = "/[^0-9a-z\s]+/i"; // Search for everything that is not alphanumeric or whitespace
$regex2 = "/\s+/"; // Search for whitespace
$regex3 = "/-+$/"; // search for trailing dashes
$text = "Hello World - This/That is (Test)";
// replace in turn, non-alpha with space, one or more spaces with dash, one or more trailing dashes with nothing
$text2 = preg_replace([$regex1, $regex2, $regex3],[' ','-',''], $text);
$text2 = strtolower($text2);
echo $text2;