Getting url adress into code?!?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Getting url adress into code?!?

Post by jmansa »

Hi. I'm trying to make my db call depending on the urladress.
I have a url adress like this:
Now I want to get "marion-city" into my script here:

Code: Select all

mysql_select_db("mydb", $con);$result = mysql_query("SELECT * FROM city WHERE cityurl=marion-city");
I want the script to be dynamic so if the cityurl is another it comes into the script automatic. I know it has something to do with "urlencode" but I dont know how?!?!? Please help!
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Post by jmansa »

For this I need more exsplanation???
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Not really - you need strpos() to get the position in the string of the text you are looking for, then substr() to get it out.
Read through the pages that Oren linked to.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You can pull the info from $_SERVER['PATH_INFO'] and split the parameters with explode('/', $_SERVER['PATH_INFO'])
see http://de2.php.net/explode and http://httpd.apache.org/docs/2.2/mod/co ... ptpathinfo
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

basename() may also be of use here.
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

you can use mod_rewrite in apache to take care of SEO urls
Post Reply