- I'm converting a user input string (successfully but...)
- I would like to ignore characters wrapped in braces
- Also remove the braces in the final output
So for instance if I have this string:
$string = "[ABC] This & Text";
function make_post_type($string) {
$needle = array('-', ' ');
$clean = preg_replace("/[^a-zA-Z0-9_\s]/", "", strtolower($string)); // Remove special characters
$haystack = preg_replace('!\s+!', ' ', $clean); // Now remove extra spaces
return str_replace($needle, '_', $haystack);
}
returns abc_this_text
I would like to return ABC_this_text