Log in

View Full Version : Need Help with Capitalization



tgallagher26
02-23-2009, 07:12 PM
Ok so my website is Kywordpro.com

I want the search query to auto capitalize the first letter to make it look more professional in other search engines an on the site.


Can anyone help with this?

Tim..

Snookerman
02-23-2009, 07:18 PM
If you want the first letter in the string to be capitalized use ucfirst (http://se.php.net/ucfirst)(). If you want to capitalize the first letter of every word use ucwords (http://se.php.net/ucwords)().

Good luck!

tgallagher26
02-23-2009, 07:38 PM
Ok Snookerman you were helpful but I still am confused.

I am not sure where to put the code since I didnt write the code for my site.

Tim..

JasonDFR
02-23-2009, 08:07 PM
Ok so my website is Kywordpro.com

I want the search query to auto capitalize the first letter to make it look more professional in other search engines an on the site.


Can anyone help with this?

Tim..

I don't understand what you are talking about. The first letter of what? As far as I know you can't control how anything looks in other search engines.

tgallagher26
02-23-2009, 08:28 PM
Ok if you visit my site you will see that whatever you search appears in the TITLE liek this.

search words :: KyWordPRO.com

I want it to look like this.

Search Words :: KywordPRO.com

Does that make more sence?

To make this happen the code in place is

<title><?php echo isset($q) ? ('' . $q) : TITLE; ?> :: KyWordPRO.com</title>

JasonDFR
02-23-2009, 08:38 PM
Change it to this:

<title><?php echo isset($q) ? ('' . ucwords($q)) : TITLE; ?> :: KywordPRO.com</title>

tgallagher26
02-23-2009, 08:52 PM
Ok so if I wanted to emplement this version

<?php
function title_case($title) {
$smallwordsarray = array(
'of','a','the','and','an','or','nor','but','is','if','then',
'else','when',
'at','from','by','on','off','for','in','out',
'over','to','into','with'
);

$words = explode(' ', $title);
foreach ($words as $key => $word)
{
if ($key == 0 or !in_array($word, $smallwordsarray))
$words[$key] = $this->my_ucwords(strtolower($word));
}

$newtitle = implode(' ', $words);
return $newtitle;
}
?>

How would I make it possible?

Nile
03-06-2009, 10:34 PM
What do you want to be capitalized? $newtitle?


return $newtitle;

To:


return ucfirst($newtitle);