Hi Malasho,
I hate to trouble you again, but is there anything in our last snippet of code that would keep $max_length from no longer working?
It seems that if I type in a 4 letter word in all caps (which isn’t defined in $capital_words), it doesn’t stay uppercase as it should be staying since it is under the $max_length limit. I tried typing “a simple TEST” and the output was “A Simple Test” where it should be “A Simple TEST”.
THANK YOU!
This is the code I have right now:
[php]if (is_subclass_of($this, ‘vB_DataManager_ThreadPost’) && is_array($this->validfields[‘title’]))
{
$this->validfields[‘title’][VF_CODE] = ’
global $exclude_words, $capital_words, $max_length;
$exclude_words = array(“a”,“an”,“and”,“at”,“but”,“by”,“for”,“in”,“nor”,“of”,“on”,“or”,“so”,“the”,“to”,“up”,“yet”); // Exclude analyzing these words
$capital_words = array(“aku”,“uhs”,“pmdc”,“ibcc”,“mcat”,“mcq”,“cmh”,“fumc”,“amc”,“nust”,“dimc”,“fmc”,“cpmc”,“hec”,“mbbs”,“ptap”,“sat”,“bds”,“kpk”,“fbise”,“lmdc”,“rmc”,“kemu”,“kemc”,“aimc”,“us”,“lums”,“sat-ii”,“plab”,“usmle”,“sims”,“smh”,“fmh”,“imdc”,“uol”,“nmc”,“cs”,“mc”,“dmc”,“imed”); // Capital exclusives (leave in lowercase in array)
$start_indicators = array(".","?","!");
$max_length = 5; // Maximum word length, anything over is case-lowered
$retval = $dm->verify_title($data);
$start = 1;
$words = explode(" ",$data);
foreach($words as $word)
{
$ignore = $do = $chunk = array();
$part = 0;
for($i=0;$i<strlen($word);$i++)
{
$char = ord($word[$i]);
if($char!= 39 && ($char<65 || ($char>90 && $char<97) || $char>122))
{
$ignore[++$part] = chr($char);
$part++;
}
else if(isset($do[$part])) $do[$part] .= chr($char);
else $do[$part] = chr($char);
}
$changed = array();
foreach ($do as $k=>$wordpart)
{
$lcWordPart = strtolower($wordpart);
if(!in_array($lcWordPart,$exclude_words) || $start == 1)
{
if(in_array($lcWordPart,$capital_words)) $changed[$k] = strtoupper($wordpart);
elseif(strlen($wordpart) > $max_length && !in_array($lcWordPart,$capital_words)) $changed[$k] = ucwords(strtolower($wordpart));
else $changed[$k] = ucwords(strtolower($wordpart));
$start = 0;
}
else $changed[$k] = strtolower($wordpart);
}
$chunk = $changed+$ignore;
ksort($chunk);
$string[] = implode($chunk);
$puncTest = substr(end($string),-1);
$start = in_array($puncTest,$start_indicators);
}
$data = implode(" ",$string);
return $retval;
';
}[/php]