Generating the title's for alot of HTML pages
I'm working with alot of files, and basically just need to know how to take the file name and add it to the title.
The files are like this for example: led_zeppelin-kashmir.html
and I would need it to automatically take the file name and add it to the title so the end result would look like this:
MySitesName.com - Led Zeppelin - Kashmir
Anyone know how to do this?
Another example just in case, would be like this...
Filename: rolling_stones-paint_it_black.html
End result for title of this html file: MySitesName.com - Rolling Stones - Paint it Black
kb posted this at 19:58 — 24th May 2004.
He has: 1,380 posts
Joined: Feb 2002
That would require a scripting language, so this needs to be moved
Greg K posted this at 21:12 — 24th May 2004.
He has: 2,145 posts
Joined: Nov 2003
The following is an example using PHP that should work, based on the following:
1. All the files will need to be changed from a .html to a .php
2. All files do have both a artist and song name
3. There is no actual use of a hyphen in the artist name or song name (I'd recommend using another character that can be used in a filename that is less likely to be used).
4. There is no error checking in this, and I haven't actually tested it.
<?php
// Set main title
$mainTitle = \"MySitesName.com\";
// Get the name of the current file, minus its extension
$curFile = basename(__FILE__, \".php\");
// Replace all the \"_\" with spaces
$curFile = str_replace(\"_\", \" \", $curFile);
// Split it up to Artist and Song by the \"-\"
list($artist,$song) = explode(\"-\",$curFile);
$fullTitle = $mainTitle . \" - \" . $artist . \" - \" . $song;
<html>
<head>
<title>= $fullTitle </title>
</head>
:
:
:
?>
For more help on how any of this works (or should work look up the commands at http://www.php.net/manual/en/.
-Greg
PS, you could also place all the PHP code (top part in the <? ?> tags, including those tags) in a file (say "buildtitle.php") and then instead on each page you would just need to do a <? include ("buildtitle.hph"); ?> at the top and set the tag on the page.
Tabble posted this at 21:16 — 24th May 2004.
They have: 10 posts
Joined: Apr 2004
Greg, thanks! I'll give it a shot!
Tabble posted this at 21:22 — 24th May 2004.
They have: 10 posts
Joined: Apr 2004
I'm pretty newbie when it comes to PHP...
I changed the extension of 1 of the files to .php, added the code, and the end result is the title being:
"?= $fullTitle ?"
Is there something else I have to do with code?
Suzanne posted this at 21:35 — 24th May 2004.
She has: 5,507 posts
Joined: Feb 2000
url?
Tabble posted this at 21:35 — 24th May 2004.
They have: 10 posts
Joined: Apr 2004
OH MY GOD IT WORKED... LOL, you have no idea how long I have been trying to fix this problem.
THANK U SO MUCH GREG!!!!!!!!
Greg K posted this at 21:42 — 24th May 2004.
He has: 2,145 posts
Joined: Nov 2003
What was the change between your two posts?
-Greg
Tabble posted this at 21:49 — 24th May 2004.
They have: 10 posts
Joined: Apr 2004
I'm gonna feel silly saying this, but I had forgotten you have to upload it to your server for php to work, lol...
I was just opening the .php with internet explorer on my computer.
(told you I was a newbie when it comes to php!)
Busy posted this at 22:31 — 24th May 2004.
He has: 6,151 posts
Joined: May 2001
you can download a php/mysql/apache bundle to your computer if you wanted, to test stuff before uploading, firepages.com.au is one of the many places that offers them.
Warning: PHP (and others) can be addicting, may cause many hours in front of your pc, your pets may disown you, you family forget who you are, you may even loose track of day and night and missing commas, quotes and/or semi commas may become the thing you dream about (nightmares), bewarned muhahahaha
Tabble posted this at 22:39 — 24th May 2004.
They have: 10 posts
Joined: Apr 2004
Just a couple more questions, if I can!
Is there any way to capitilaze the first letter of each word?
Just to make it look a little more professional...
Cause right now the title it's showing looks like this for example:
MySitesName.com - rolling stones - paint it black
Is it possible to make it:
MySitesName.com - Rolling Stones - Paint It Black ?
2nd question:
Is there a way, using PHP, to make navigational, kind of "you are here" links somewhere in the file, that would look like this:
(Using the same example, if you were looking at Rolling Stones, Paint it Black file)
MySitesName.com
MySitesName.com - R
MySitesName.com - R - Rolling Stones
MySitesName.com - R - Rolling Stones - Paint It Black (This one would just be text, no link)
These aren't absolutely necessary, so if it's difficult to do, nevermind...
Thanks again.
andy206uk posted this at 09:58 — 27th May 2004.
He has: 1,758 posts
Joined: Jul 2002
Yup... use the ucwords() function ie: (add the following at the bottom of the large block of php).
$fullTitle = ucwords($fullTitle);
'Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.