/    Sign up×
Community /Pin to ProfileBookmark

getting data from url

url like property/rent/apartment/banglore.html…

i want to get the values like rent,apartment,banglore from the url and be stored in variables….
in the form i used post method..
based on this values the data searches the database and displays the result…

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ericatekkaFeb 22.2010 — I'd do soemthing like SERVERURL then explode it. then store each array into its own variable.
Copy linkTweet thisAlerts:
@ericatekkaFeb 22.2010 — Lets say the url is /property/rent/apartment/banglore.html

$url = $_SERVER['PHP_SELF'];

$urlstr = explode($url,"/");

$prop = $urlstr[0];

$type = $urlstr[1];

$apartment = $urlstr[2];

$lastone = explode($urlstr[3],".");

$last = $lastone[0];
Copy linkTweet thisAlerts:
@MindzaiFeb 22.2010 — ^^^

That won't get you the requested URL, just the URL of the currently executing script.

@OP, I assume this is coming in via a rewrite like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>


You can then explode on the slash to get the URL parts, but I think you need to clarify your requirements a bit more - will the URL always follow this exact structure? What happens if the URL has fewer elements? If the URL is not coming via rewrite, where is the value coming from?
Copy linkTweet thisAlerts:
@criterion9Feb 22.2010 — I'd use mod_rewrite (assuming apache) and convert them into GET variables. That is probably the easiest way and doesn't require any extra coding in the application.
×

Success!

Help @mlokeishreddy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...