Forum Moderators: coopster
<?php
$a = strtolower(Hello_+ Wo--rld");
$b = str_ireplace('_','-',$a);
$c = str_ireplace(' ','-',$b);
$d = preg_replace('/[--]+/','-',$c);
$e = preg_replace('/[^a-z0-9-]/','',$d);
$f = trim($e,'-');
echo $f;
?>
$d = preg_replace('/[--]+/','-',$c); doesn't do what you think it does. [<stuff>] creates a character class. What that means is it matches a single character, among essentially a list of characters. For instance, [A-Z] matches any character between A and Z. [--] doesn't match two consecutive dashes, it matches a dash. So [--]+ is equivalent to [-]+, which matches one or more dashes. /--+/ or /[-]{2,}/ to match two or more dashes.