3v4l.org

run code in 300+ PHP versions simultaneously
<?php function make_post_type($s) { preg_match_all("~({[^{}]*}|\[[^][]*])|[\w\s]+~", $s, $m); $s = ''; foreach($m[0] as $k => $v) { $s .= (bool) $m[1][$k] ? substr($v, 1, -1) : strtolower($v); } return preg_replace('~[-\s]+~', '_', $s); } echo make_post_type("[ABC] This & Text");

preferences:
32.88 ms | 407 KiB | 5 Q