I need a PHP hack that does the following: -Changes the first letter of every word in a sentence to uppercase -Ignores certain defined short words (a, of, the, etc) and leaves them lowercase. -Ignores certain defined all caps words (USA, IMHO, BRB, etc) and leaves them capitalized. -Ignores capitalized words that are X number of characters or less and leaves them capitalized. -Correctly handles punctuation marks at the end of a word (comma, question mark, exclamation, etc) PM me with a price and send me your skype details if you have one so we can discuss further. I need this done today and will pay today! I have plenty of positive feedback on here -- just look at my previous posts. Thank you!
<?php $string = "this is a test string"; // Your input string $exclude_words = array("the","a","of","is"); // Exclude analyzing these words $max_length = 10; // Maximum word length, anything over is ignored $parts = explode(" ",$string); foreach ($parts as $word) { if (!in_array(strtolower($word),$exclude_words) && strlen($word) <= $max_length) { $first_letter = substr($word,0,1); $newWord = strtoupper($first_letter).substr($word,1); $string = str_replace($word,$newWord,$string); } } echo $string; // This should output "This is a Test String" ?> Code (markup): Untested, but should work & suit your needs.
So many thanks to Syndication -- this guy is a complete all star! Helped me out and was so nice and generous with his time!!!
Of course its untested, simple copy and paste of someone else's work. There are many other ways to go about this that will actually shorten the amount of code. Next time try posting the article URL with your source, some people put serious effort into developing these snipits and they share it because its a passion to them. http://pastebin.com/XtYiTyfy Simple google search on mostly anything you find now a days will give you the heads up if your buying someone elses work or something that you could have read up on yourself.