Forum Moderators: coopster

Message Too Old, No Replies

Displaying the parent folders name

How to do it with PHP?

         

PFOnline

12:39 am on Jun 3, 2004 (gmt 0)

10+ Year Member



Say there is an url like this for example:

www.mydomain.com/pics/b/basketball/index.php

using php, is there a way to just display the word basketball in the index.php file?

I would also need to display it in the title tags like this: <title>Basketball pics</title>

WhosAWhata

2:20 am on Jun 3, 2004 (gmt 0)

10+ Year Member



i don't know if PHP can do that
.htaccess files could send those variables to it though

RewriteEngine on
RewriteRule (.*)/(.*)/(.*)/index.php $1/$2/$3/index.php?title=$3&nbsp;$1

probably not the best way to do it though

i think realpath() [php.net] might be the way to go actually

coopster

2:48 pm on Jun 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's not pretty...
$dirs = explode [php.net]('/', dirname [php.net]($_SERVER [php.net]['PHP_SELF'])); 
print '<title>' . $dirs[count [php.net]($dirs) - 1] . ' pics</title>';
...but it works.

PFOnline

8:11 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



Thanks, it works, but I'm just having 1 problem...

Some of the directory names are like this for example:

www.mydomain.com/pics/p/ping_pong/

So the title is ending up looking like this: ping_pong Pics

Rather than what I would hope: Ping Pong pics

So, using the same code:


$dirs = explode('/', dirname($_SERVER['PHP_SELF']));
print '<title>' . $dirs[count($dirs) - 1] . ' pics</title>';

What would I add to make it a space rather than a _?

Does anyone know?

jatar_k

8:21 pm on Jun 3, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$formatdir = ucfirst(str_replace("_"," ",$dirs[count($dirs) - 1]));
print '<title>' . $formatdir . ' pics</title>';
I think that's right

<added>sorry ucwords is right, not ucfirst, as WhosAWhata points out

[edited by: jatar_k at 8:23 pm (utc) on June 3, 2004]

WhosAWhata

8:21 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



$dirs = explode('/', dirname($_SERVER['PHP_SELF']));
$echo = ucwords(ereg_replace("_"," ",$dirs[count($dirs) - 1]));
print '<title>' . $echo . ' pics</title>';

PFOnline

8:27 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



That did the trick, thanks jatar, Whosawhata! :)

PFOnline

11:46 pm on Jun 3, 2004 (gmt 0)

10+ Year Member



OK I'm now just 1 question away from being done making my website, after 2 months of work!

This was a large project, I've never made a website like this before...

It's actually a guitar tablature website, with over 20,000 php pages...

I think this is a rather difficult question, and I'm not even sure if it can be done...

But we'll find out I guess... :)

OK, within the index.php files, is a listing of links that look like this for example:

rolling_stones-paint_it_black [mydomain.com]

rolling_stones-ruby_tuesday [mydomain.com]

What'd I'd like the links to say are "Paint It Black Tab" and "Ruby Tuesday Tab", so it would have to somehow cut off, or not display all the text before the " - " for every link, capitalize the beginning of every word, change the _'s to spaces, and add the word "Tab" after ever link.

Yikes huh?

These links are allready pre-generated and embedded into the files, and there's no way I can make them generate anything other than like the examples above.

Does anyone know how to do this? Is it even possible?