Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $string = "this is a test STRING BRB LOL"; // Your input string
- $exclude_words = array("the","a","of","is"); // Exclude analyzing these words
- $capital_words = array("brb","lol"); // Capital exclusives (leave in lowercase in array)
- $max_length = 5; // Maximum word length, anything over is case-lowered
- $parts = explode(" ",$string);
- foreach ($parts as $word) {
- if (!in_array(strtolower($word),$exclude_words)) {
- $old_word = $word;
- $first_letter = substr($word,0,1);
- if (strlen($word) >= $max_length && !in_array(strtolower($word),$capital_words)) { $word = strtolower($word); }
- if (in_array(strtolower($word),$capital_words)) { $word = strtoupper($word); }
- $newWord = strtoupper($first_letter).substr($word,1);
- $string = str_replace($old_word,$newWord,$string);
- }
- }
- echo $string; // This should output "This is a Test String"
- ?>
Advertisement
Add Comment
Please, Sign In to add comment