Okay, cool. I though I needed to escape the period, but I tested it without and it works just fine. I also got rid of the unnecessary modifier at the end of the regex as well as well. Hooray, two less characters!
Thanks for the explanation for the whole while(strpos()) thing. Makes sense now. I also reversed the order of last bit, removing multiple spaces. Now it removes multiple hyphens, which prevents converting something like hey o- mate into hey-o--mate.php. So here's what I've got now.
PHP Code:
$page = preg_replace('/[^a-z0-9-. ]/', '', strtolower($page)); $page = str_replace(' ', '-', trim($page)); while (strpos($page, '--') !== false) $page = str_replace('--', '-', $page); if(!preg_match('/\.php$/', $page)) { $page = $page.".php"; }
Thanks for all the help!
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
Last edited by stevej; 06-10-2009 at 04:47 PM..
|