Forum Moderators: coopster
$new_url = preg_replace("/\s/", "-", $url);
Don't know why you have spaces in your url's. This is an attempt at replacing all those within double quotes "http://[...]" - and not, e.g., those just in ordinary text - reason being that if you've got spaces in your url's, how do you tell from [this...] . com / some kind of url . html from ordinary text? unless you mean urlencoded spaces like %20 or whatever, but that's a different story.
Didn't try this regex out, check it first, I often make mistakes. Function declaration necessary since this is a callback function.
$html = preg_replace("/(href[\s\n\r\t]*=[\s\n\r\t]*[\'\"])([^\'\"]{3,})([\'\"])/ie", "\"$1\".str_replace(\" \", \"-\", \"$2\").\"$3\"", $html);
Believe it or not. I'm not going to bother explaining it, LOL. Trust me, it works. I just did a quick test and it worked.