PhpDig.net

PhpDig.net (http://www.phpdig.net/forum/index.php)
-   Coding & Tutorials (http://www.phpdig.net/forum/forumdisplay.php?f=31)
-   -   regex for trailing slashes? (http://www.phpdig.net/forum/showthread.php?t=1566)

leonardburton 12-03-2004 01:46 AM

regex for trailing slashes?
 
Could someone please help me come up with a regex to determine if a trailing slash needs to be added to a url?

for instance http://www.whatever.com needs to become http://www.whatever.com/

and http://www.whatever.com/foo needs to be http://www.whatever.com/foo/

but http://www.whatever.com/foo.php needs to remain the same

Thanks,

Leonard

Charter 12-03-2004 03:06 AM

PHP Code:

// assumes all filenames are of name.ext format
$url "http://www.domain.com";
$part pathinfo($url,PATHINFO_EXTENSION);
$last substr($url, -1);
if ((
$last != "/") && (empty($part['extension']))) {
$url $url."/";
}
echo 
$url



All times are GMT -8. The time now is 01:35 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.