dzedward Posted January 9, 2008 Share Posted January 9, 2008 Right now I'm using the code below to get the URL of the current page... what I'd like to do is get a specific portion, what I want is highlighted in bold in the below URL http://www.site.com/folder/file.html <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> <?php echo curPageURL(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/85109-get-specific-part-of-url/ Share on other sites More sharing options...
dzedward Posted January 9, 2008 Author Share Posted January 9, 2008 If it makes it easier, i'll know what the http://www.site.com and file.html will be, just need to know the folder name Quote Link to comment https://forums.phpfreaks.com/topic/85109-get-specific-part-of-url/#findComment-434141 Share on other sites More sharing options...
teng84 Posted January 9, 2008 Share Posted January 9, 2008 $x = explode('/',$_SERVER['REQUEST_URI']); echo $x[1]; maybe Quote Link to comment https://forums.phpfreaks.com/topic/85109-get-specific-part-of-url/#findComment-434145 Share on other sites More sharing options...
kenrbnsn Posted January 9, 2008 Share Posted January 9, 2008 Take a look at the following functions: parse_url() pathinfo() dirname() basename() One of them or a combination should be able to give you what you want. Ken Quote Link to comment https://forums.phpfreaks.com/topic/85109-get-specific-part-of-url/#findComment-434147 Share on other sites More sharing options...
Stooney Posted January 9, 2008 Share Posted January 9, 2008 Slightly less conventional way...I'm sure nobody would agree with this, but it's simple (assuming that the folder is the only unknown part of the string) $url = "http://www.site.com/folder/file.html $trim=ereg_replace("http://www.site.com/", "", $url); $folder=ereg_replace("/file.html", "", $trim); Quote Link to comment https://forums.phpfreaks.com/topic/85109-get-specific-part-of-url/#findComment-434152 Share on other sites More sharing options...
dzedward Posted January 9, 2008 Author Share Posted January 9, 2008 thanks chrisdburns, that works for me perfect. I will always know the site and file, so this is perfect. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/85109-get-specific-part-of-url/#findComment-434158 Share on other sites More sharing options...
teng84 Posted January 9, 2008 Share Posted January 9, 2008 thanks chrisdburns, that works for me perfect. I will always know the site and file, so this is perfect. Thanks again. thats should work but bad habit.. using regex is slow if that is waht you want then just use string function string functions can do that Quote Link to comment https://forums.phpfreaks.com/topic/85109-get-specific-part-of-url/#findComment-434161 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.