I have been working on a script for a few days now whioch basically capitalizes the first letter of all english dictionary words. For example: hellotheremynameis > HelloThereMyNameIs. Although some parts of my script is coming together, the loading time is way too long. So im looking for some sort of function or a solution that would help me make a script that would capitalize the first letter of english words even when there is no space. Any help is greatly appreciated!
That would be hard one because even a simple word there is words inside of words. hellotheremynameis hello there my name is Hell Lot He Me Am The Here other A I and that is just what I can find. So, you will have to program some intelligence into the script to figure out what they are trying to say and then upper case those words. Otherwise your just going to have a mess on your hands. If you must the very LONG way to do it would be to load the dictionary into a mysql db and then loop through the entire db for each word. Very long and bad yep. strpos will help with finding the words.
You might be able to do this with reasonable speed and accuracy. First, split your dictionary into 26 arrays by the first letter of each word. Then sort each of those arrays by word length in descending order. Then successively test your subject string to find the dictionary words at the start of the subject string. If a dictionary word is found at the start of the subject string, add the ucfirst() version of the dictionary word to the end of your result string and strip the dictionary word off the start of the subject string. If no dictionary word is found at the start of the subject string, check for common words (a, an, and, but, is, if, of, the, with, when, where, why, etc.). If a common word is found, treat it like a dictionary word and proceed. If no match is found either in the dictionary or in your common words, treat the remainder of the subject text as a dictionary word and stop processing.