Generating the title's for alot of HTML pages<

liunx

Guest
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 BlackWhat server-side scripting language are you going to be using to accomplish this? You could do this with Javascript too from the client-side. However if you want to do it server-side (which is a lot better in this case), then tell us what languages you are willing to work with and if you don't know, the tell us what is supported by your server! :) (e.g. ASP, PHP, Perl, etc...)Hi Anthony, I just figured out how to do it with PHP!

So scratch that question, but I have another question if i can!

Here's the code that did the trick:

<?
// 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>


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 ?Originally posted by Tabble
Hi Anthony, I just figured out how to do it with PHP!

So scratch that question, but I have another question if i can!


I'd love to help you, but I don't know much about PHP! :( I'm sure someone will help you out soon enough though! :)Ucfirst(STRING) -- Returns a string with the first letter of STRING in uppercase. For instance, ucfirst("abcd") returns "Abcd"


that should do itActually Kram, I think a better method would be
ucwords($string)
as this capitalizes the first letter of every word in the string whereas ucfirst only capitalizes the first letter in the string

Here is the php.net example:
<?php
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!

$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>Well i didnt even know that function existed, good one Bica! :)It's a handy-dandy little tool eh?yeah that may actually come in handy with my project...coolHey, thanks for the ucwords code. :)

But i've tried it a bunch of different ways and can't seem to get it to work.

Will it work with the title tags?

Maybe you can tell me, using this code:



<?
// 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>


Where you would put the ucwords code and what the code would be? To get the first letter of every word in the title to be upper case.

I tried $artist = ucwords($artist)

and a couple of variations of that... Am I way off?

Cheers!<title><?= ucwords($fullTitle) ?></title>Thanks scoutt! It worked! :)!? sigh if only I could test my PHP.Get phpdev or install apache and php standalone.
 
Back
Top