Page 1 of 2
Stripping URL information into variables
Posted: Tue Jun 08, 2004 6:27 am
by SFADuncan
How do I take the URL of a current page and strip it into different parts
I'm trying to isolate the directory path of the url of a current page
eg
http://www.domain.co.uk/directory
I wish to isolate "directory" and make it equal a variable.
Simon
Posted: Tue Jun 08, 2004 6:40 am
by launchcode
Posted: Tue Jun 08, 2004 6:41 am
by feyd
[php_man]parse_url[/php_man]()
Posted: Tue Jun 08, 2004 6:41 am
by feyd
phooey!

Posted: Tue Jun 08, 2004 6:45 am
by launchcode
Beat yah! by at least.. ohhh.. 40 seconds

Posted: Tue Jun 08, 2004 7:49 am
by SFADuncan
Hi thanks for these links... I had seen them... but was put off by the very first comment in the User Contributed Notes
"Its all very well being able to split and reconstruct a url. BUT how on earth do you get the FULL url of the current page."
since it is exactly this which I am trying to do.... but I will ignore this comment and attempt to use what is listed on this page
Posted: Tue Jun 08, 2004 8:21 am
by SFADuncan
No luck... all the scripts I see involve typing in the URL (within the script) ... I want to use the URL of the current page
Posted: Tue Jun 08, 2004 8:51 am
by SFADuncan
This script almost works:
<?php
echo "Current directory is " . getcwd();
?>
Except that I get:
Current directory is /home/virtual/site214/fst/var/www/html/test
when all I want is:
Current directory is test
Any ideas?
Simon
Posted: Tue Jun 08, 2004 9:17 am
by Grim...
Ugly but quick:
Code: Select all
$url = getcwd();
$array = explode ("/", $url);
$arrayB = array_reverse($array);
$folder = $arrayB[0];
Posted: Tue Jun 08, 2004 9:41 am
by jason
Okay, how is the cwd the same thing as trying to get the URL and parsing that? I am sorry, but if you are going to ask the question, ask the right question.
What are you trying to accomplish? Don't tell me what you think the solution is, tell me what you want.
Posted: Tue Jun 08, 2004 9:42 am
by pickle
Look at the $_SERVER variables. There's one in there about the script_uri.
Posted: Tue Jun 08, 2004 9:43 am
by jason
Posted: Tue Jun 08, 2004 9:58 am
by Grim...
jason wrote:I am sorry, but if you are going to ask the question, ask the right question.
To be fair, he did ask the right question.
He said:
SFADuncan wrote:I'm trying to isolate the directory path of the url of a current page
getcwd() is one way of achieving this.
Posted: Tue Jun 08, 2004 10:31 am
by redmonkey
You could try...
Code: Select all
<?php
$pwd = pathinfo(getcwd());
$cwd = $pwd['basename'];
echo $cwd;
?>
Although this will probably give undesireable results if run in your www root.
Posted: Tue Jun 08, 2004 11:51 am
by launchcode
What the hell? Why mess with cwd? To get the "full" URL of the current page on your site, just combine two values:
$_SERVER['HTTP_HOST'] and either $_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'] if you need all the query string values.
Merge the two and kick the result to parse_url.