Les_N00bian
asked on
Can you grab a folder name from a URL and pass that to a PHP variable?
I'm wondering if you can grab a folder name from a URL and pass that to a PHP variable? For example, suppose I have mydomain.com/new-york/ and in that directory I have index.php and that page has a variable in it, say $cityname. Instead of setting $cityname manually, could I have it look at the folder that it resides in, "new-york", and pull that as the value for $cityname?
Yes there is a PHP variable: $_SERVER["REQUEST_URI"] that contains the URI of the current URL. From there you can use string/regex parsing to just grab the city. How you do this will depend on the path of your URI
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.