# Define our test post. Of course replace this with your text. $post = 'Hey there this is a Set of Words, grouped into a sentence. I think This Is pretty Cool!'; # Define our alphabet for character names $chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); # Convert all spaces (\n, \t, etc.) to single spaces $post = preg_replace("#\s#i", ' ', $post); # Double check to make sure double spacing doesn't occur while( strstr($post, ' ') ) { $post = str_replace(' ', ' ', $post); // Replace double spaces } # Replace punctuation $disallowed = array('.', ',', '!', '?', ';'); // You can add more characters to this array. # Get rid of the punctuation $post = str_replace($disallowed, '', $post); # If you want the string to be all lowercase, uncomment the next line. # $post = strtolower($post); # If you want the string to be all uppercase, uncomment the next line. # $post = strtouppwer($post); # If you want the first letter of each word to be capitalized, uncomment the next line. # $post = ucwords($post); # Split the string $words = explode(' ', $post); # If you actually want to define them like $a = 'hey', $b = 'there' then uncomment what's below. /* for($i = 0; $i < sizeof($words); $i++) { $$chars[$i] = $words[$i]; } */