MDanz Posted August 23, 2009 Share Posted August 23, 2009 echo 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; this gives me the url currently in my address bar. is there anyway to select a certain part of it. like it returns... www.example.com and i only want 'example'. ?? Link to comment https://forums.phpfreaks.com/topic/171517-solved-select-certain-part-of-url/ Share on other sites More sharing options...
Mark Baker Posted August 23, 2009 Share Posted August 23, 2009 The parse_url() function allows you to extract the domain from a full url. Then you can just explode it on the . and extract the element you want from the resultant array Link to comment https://forums.phpfreaks.com/topic/171517-solved-select-certain-part-of-url/#findComment-904447 Share on other sites More sharing options...
MDanz Posted August 23, 2009 Author Share Posted August 23, 2009 srry bad example.. e.g. http://www.example.com/reply.php?reply=Hello&submit=reply i want the 'Hello' part from the url Link to comment https://forums.phpfreaks.com/topic/171517-solved-select-certain-part-of-url/#findComment-904449 Share on other sites More sharing options...
thebadbad Posted August 23, 2009 Share Posted August 23, 2009 Use a combination of parse_url() and parse_str(): $url = 'http://www.example.com/reply.php?reply=Hello&submit=reply'; parse_str(parse_url($url, PHP_URL_QUERY), $output); echo $output['reply']; //Hello Link to comment https://forums.phpfreaks.com/topic/171517-solved-select-certain-part-of-url/#findComment-904453 Share on other sites More sharing options...
MDanz Posted August 23, 2009 Author Share Posted August 23, 2009 thx ALOT! it works! Link to comment https://forums.phpfreaks.com/topic/171517-solved-select-certain-part-of-url/#findComment-904458 Share on other sites More sharing options...
papaface Posted August 23, 2009 Share Posted August 23, 2009 or maybe just echo $_GET['reply']; If you're wanting the value of "reply" in the url of the page displayed. Link to comment https://forums.phpfreaks.com/topic/171517-solved-select-certain-part-of-url/#findComment-904464 Share on other sites More sharing options...
thebadbad Posted August 23, 2009 Share Posted August 23, 2009 or maybe just echo $_GET['reply']; If you're wanting the value of "reply" in the url of the page displayed. Ah yes. Overlooked that the OP probably is on the page where the query string is set. Link to comment https://forums.phpfreaks.com/topic/171517-solved-select-certain-part-of-url/#findComment-904471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.