PhpDig.net

Go Back   PhpDig.net > General Forums > Coding & Tutorials

Reply
 
Thread Tools
Old 12-03-2004, 01:46 AM   #1
leonardburton
Green Mole
 
Join Date: Dec 2004
Posts: 10
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
leonardburton is offline   Reply With Quote
Old 12-03-2004, 03:06 AM   #2
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
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
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Points, underscores, ampersands and slashes renehaentjens Mod Requests 1 12-08-2003 01:00 PM


All times are GMT -8. The time now is 10:18 AM.


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