Guest User

Untitled

a guest
Sep 25th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2. $string = "this is a test STRING BRB LOL"; // Your input string
  3. $exclude_words = array("the","a","of","is"); // Exclude analyzing these words
  4. $capital_words = array("brb","lol"); // Capital exclusives (leave in lowercase in array)
  5. $max_length = 5; // Maximum word length, anything over is case-lowered
  6.  
  7. $parts = explode(" ",$string);
  8. foreach ($parts as $word) {
  9.  if (!in_array(strtolower($word),$exclude_words)) {
  10.   $old_word = $word;
  11.   $first_letter = substr($word,0,1);
  12.   if (strlen($word) >= $max_length && !in_array(strtolower($word),$capital_words)) { $word = strtolower($word); }
  13.   if (in_array(strtolower($word),$capital_words)) { $word = strtoupper($word); }
  14.   $newWord = strtoupper($first_letter).substr($word,1);
  15.   $string = str_replace($old_word,$newWord,$string);
  16.  }
  17. }
  18.  
  19. echo $string; // This should output "This is a Test String"
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment