| Title Tag Problem
|
mkingsle

msg:3734580 | 7:08 pm on Aug 29, 2008 (gmt 0) | Hi All: I have the following code in a file to populate the title for each web page: <?php //this part remains the same $title = basename($_SERVER['SCRIPT_NAME'], '.php'); $title = str_replace('_', ' ', $title); //below are changes $title = strtolower($title); $titleArr = explode(" ", $title); //creating an array of words from $title $strToCaps= array("II", "php", "html"); //words to strtoupper() //running strtoupper() with all words found in $strToCaps and ucwords() for all others foreach(array_keys($titleArr) as $key){ if(in_array($titleArr[$key], $strToCaps)){ $titleArr[$key] = strtoupper($titleArr[$key]); } else{ $titleArr[$key] = ucwords($titleArr[$key]); } } //reforming the string $newTitle = implode(" ", $titleArr); ?> My issue is that I have a lot of webpages with the word "and" in them, and with the above code, it capitalizes each word, including "and". Is there a piece of code that I can put in the above file to segregate the word "and" to make it lowercase. Thanks, Michael
|
shdwmage

msg:3734617 | 7:51 pm on Aug 29, 2008 (gmt 0) | I am not sure if this will work or not, its just what popped into my head, but couldn't you try a: $newTitle = str_replace('AND', 'and', $newTitle);
After reforming the string?
|
mkingsle

msg:3734673 | 9:16 pm on Aug 29, 2008 (gmt 0) | Well, I think I got it figured out, with you help, and adding one piece of code. It might be wrong, but it worked. Let me know if there is an easier way. <?php //this part remains the same $title = basename($_SERVER['SCRIPT_NAME'], '.php'); $title = str_replace('_', ' ', $title); //below are changes $title = strtolower($title); $titleArr = explode(" ", $title); //creating an array of words from $title $strToCaps= array("and", "II", "php", "html"); //words to strtoupper() added "and" here to cap it //running strtoupper() with all words found in $strToCaps and ucwords() for all others foreach(array_keys($titleArr) as $key){ if(in_array($titleArr[$key], $strToCaps)){ $titleArr[$key] = strtoupper($titleArr[$key]); } else{ $titleArr[$key] = ucwords($titleArr[$key]); } } //reforming the string $newTitle = implode(" ", $titleArr); $newTitle = str_replace('AND', '&', $newTitle); //added code you mentioned here, changing capped "AND" to the "&" symbol ?>
|
shdwmage

msg:3734743 | 11:44 pm on Aug 29, 2008 (gmt 0) | I thought you had said it was always capped, but yes it is a good idea to insure that is capped if you are going to do the string replace with the ampersand. I'm glad to have been of assistance.
|
|
|