3v4l.org

run code in 300+ PHP versions simultaneously
<?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;

preferences:
29.34 ms | 402 KiB | 5 Q