php regex replace slashes and spaces and hyphens
- by Muhammad Shahzad
I have fews combinations of strings that I need to bring in to one pattern, that is multiple spaces should be removed, double hyphens should be replaced with single hypen, and single space should be replaced with single hyphen.
I have already tried this expression.
$output = preg_replace( "/[^[:space:]a-z0-9]/e", "", $output );
$output = trim( $output );
$output = preg_replace( '/\s+/', '-', $output );
But this fails in few combinations.
I need help in making all of these combinations to work perfectly:
steel-black
steel- black
steel black
I should also remove any of these as well "\r\n\t".