You are here:  » How do I convert the first letter of each searched word into a capital?

Support Forum



How do I convert the first letter of each searched word into a capital?

Submitted by GemViper on Thu, 2010-04-29 23:12 in

I love this software!

I'm sorry for asking so many questions but I stumbled upon a little issue with the search feature.

When someone looks up "blue jeans" they end up at a page with the title "blue jeans" and the url includes "blue-jeans". The problem I'd like to fix is that if someone also looks up "Blue Jeans" they end up on a page with the title "Blue Jeans" and the url includes "Blue-Jeans".

Both pages are identical of course but Google treats the url's as separate and doesn't always use the capitalized version so search results are mixed (in my case so far).

A quick conversion to capitalize the first letter of every searched word before passing it onto $q would be great, what would you suggest is the best way to do this?

Thanks in advance.

Submitted by support on Fri, 2010-04-30 08:39

Hello Steph,

URLs are a little tricker as bear in mind that the search.php?q=Key+Words is generated directly from what the user enters; so the safest way to adjust the keywords as they appear in the URL would actually be to add an intermediate handler script that redirects to a Name Cased version of the query.

The script would be simply (for example):

searchsubmit.php:

<?php
  
require("includes/common.php");
  
$q $_GET["q"];
  
$q ucwords(strtolower($q));
  
header("Location: ".$config_baseHREF."search.php?q=".urlencode($q));
  exit();
?>

And then in html/searchform.php, look for the following code on line 2:

  <form name='search' action='<?php print $config_baseHREF ?>search.php'>

...and REPLACE with:

  <form name='search' action='<?php print $config_baseHREF ?>searchsubmit.php'>

Hope this helps!

Cheers,
David.