3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "(Here {is [a] Special} Title)! & it's fine, right?"; echo preg_replace('~[^a-z]~', '_', strtolower($string)); // all non-letters become underscores echo "\n\n"; echo str_replace(' ', '_', preg_replace('~[^a-z ]+~', '', strtolower($string))); // notice the consecutive underscores echo "\n\n"; echo preg_replace(['~[^a-z ]+~', '~ +~'], ['', '_'], strtolower($string)); // notice no consecutive underscores

preferences:
113.87 ms | 406 KiB | 5 Q