OK, I left it out of the wrapper, since I can’t test it in the wrapper.
There may be a better way, but this is the first working version I came up with…
[php]<?php
global $exclude_words, $capital_words, $max_length;
$data = “this is my hyphen-word sentence. that better be OK with you! lol”;
$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(“brb”,“lol”,“usa”); // Capital exclusives (leave in lowercase in array)
$max_length = 5; // Maximum word length, anything over is case-lowered
global $exclude_words, $capital_words, $max_length ;
$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<65 || ($char>90 && $char<97) || $char>122)
{
$ignore[++$part] = chr($char);
$part++;
}
else $do[$part] .= chr($char);
}
$changed = array();
foreach ($do as $k=>$wordpart)
{
if(!in_array(strtolower($wordpart),$exclude_words))
{
if(in_array(strtolower($wordpart),$capital_words)) $changed[$k] = strtoupper($wordpart);
elseif(strlen($wordpart) >=$max_length && !in_array(strtolower($wordpart),$capital_words)) $changed[$k] = ucwords(strtolower($wordpart));
else $changed[$k] = ucwords($wordpart);
}
else $changed[$k] = strtolower($wordpart);
}
$chunk = $changed+$ignore;
ksort($chunk);
$string[] = implode($chunk);
}
echo implode(’ ',$string);[/php]
This could continue to grow indefinitely! For instance, what about foreign character sets, etc.
Let me know if this works for you, and if you see any other rules or changes that need to be implemented!
I didn’t comment the code, so if you want any explanations please let me know, I’d be happy to do so.