Frank
Frank

Reputation: 41

PHP - Get string from URL

by having an URL like this: mysite.com/subfolder/helloworld - Is it possible to read the "helloworld" from within a PHP page?

I would like to use the string as a part to load some content.

Upvotes: 3

Views: 10626

Answers (4)

Piyush Nayee
Piyush Nayee

Reputation: 1

Hello have u used 'strstr' keyword of php? please try like this

if(strstr($_SERVER["REQUEST_URI"], "helloworld"))
    return true;
else
    return false;

May be this will be helpful to you.

Upvotes: 0

Arjan
Arjan

Reputation: 9884

The request url (everything from the first / after the domain name) can be found in $_SERVER["REQUEST_URI"]

Upvotes: 0

Galen
Galen

Reputation: 30170

end( explode( '/', $_SERVER['REQUEST_URI'] ) )

without the end() call it will give you all the parts of the URL

Upvotes: 2

Matthieu Napoli
Matthieu Napoli

Reputation: 49703

You should read about URL rewriting.

This is more clean than "reading" the current URL. Basically you can redirect your URL (transparently) to something like :

mysite.com/index.php?folder=subfolder&category=helloworld

Then in PHP, you can access the URL parameter with :

$folder = $_GET['subfolder']
$category = $_GET['category']

This is maybe not the kind of answer you were expecting, but it can be interesting to know.

Upvotes: 0

Related Questions