title dynamic - half way there

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
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

title dynamic - half way there

Post by gaogier »

I have created this.

http://pastebin.com/5fFdT6n6

I now need to get the title of the guide type showing.

Example, http://runehints.com/quests/149/All_Fired_Up - the title should be .:RuneHints:. Quests - All Fired Up
http://runehints.com/quests/114/Another_Slice_of_H.A.M. would be .:RuneHints:. Quests - Another Slice of H.A.M.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: title dynamic - half way there

Post by Celauran »

Have you tried exploding $_SERVER['REQUEST_URI'] and then removing the underscores with str_replace?
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Re: title dynamic - half way there

Post by gaogier »

Sorry, I am a novice at php, I am proud I managed the first step.

I am googling what you said :D
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: title dynamic - half way there

Post by Celauran »

$_SERVER['REQUEST_URI'] will contain a string like /quests/149/Whatever
Use explode() with / as a delimiter to break apart the string into an array. The last element in the array will be your quest name. Finally, you can use str_replace() to replace the underscores with spaces, and there's your page title.
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Re: title dynamic - half way there

Post by gaogier »

Do you have an example, I am trying to find one online but not sure
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: title dynamic - half way there

Post by Celauran »

Try something like this:

Code: Select all

$uri = $_SERVER['REQUEST_URI'];
$parts = explode("/", $uri);
$title = $parts[count($parts) - 1];
$title = str_replace("_", " ", $title);
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Re: title dynamic - half way there

Post by gaogier »

Thanks for your help. Problem resolved :D
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: title dynamic - half way there

Post by McInfo »

Some other functions to be aware of:
Post Reply