Forum Moderators: coopster
<?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
<?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
?>