bsamson Posted November 28, 2006 Share Posted November 28, 2006 Hello ... I have the following URL: http://www.mydomainname.com/about.php I would like to find out how to grab just the [i]about.php[/i] and store it in $pgfile. The only other thing is occasionally there are variables that get passed through the URL, for example: http://www.mydomainname.com/about.php?r=4&yu-8 Even with the above case I would like to be able to grab just the [i]about.php[/i] and store it in $pgfile. Any assistance would be greatly appreciated! Thanks in advance! Quote Link to comment Share on other sites More sharing options...
trq Posted November 28, 2006 Share Posted November 28, 2006 [code=php:0]$pgfile = basename("http://www.mydomainname.com/about.php");[/code] Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 28, 2006 Author Share Posted November 28, 2006 Thanks for the help. Here's what I came up w/ for code:[code]<?$pgfile = basename($REQUEST_URL);echo $pgfile;?>[/code]Now this works in grabbing the [i]about.php[/i] ... But, if I have this url:http://www.mydomainname.com/about.php?var1=blah&var=blahit grabs [i]about.php?var1=blah&var=blah[/i] in $pgfile ...Now the url doesnt always have the variables ... but when it does I would like for it to just grab about.php. Any suggestions how I can get this to work? Thanks again in advance! Quote Link to comment Share on other sites More sharing options...
Orio Posted November 28, 2006 Share Posted November 28, 2006 This worked for me :)[code]<?phpfunction clean_name($url){ $url=basename($url); $temp = explode("?",$url); return $temp[0];}?>[/code]Orio. Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 28, 2006 Author Share Posted November 28, 2006 Hey Orio! Thank you for the code! Appreciate it! Quote Link to comment Share on other sites More sharing options...
Orio Posted November 28, 2006 Share Posted November 28, 2006 I have a little addition, to avoid urls like http://www.domain.com/page.htm#top[code]<?phpfunction clean_name($url){ $url=basename($url); $temp = explode("?",$url); $temp2 = explode("#",$temp[0]); return $temp2[0];}?>[/code]Orio. Quote Link to comment 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.