Fun stuff to try. This sort of works. I like my friends when I attach this script to the text area and let them "translate" things. I think you could use it for something really. Fur. Check the code a few times, if you intend to use it, it works, but I'm new to all of this. I think 2 or 3 weeks have passed since I started learning php.
<?php $html = ('<div style="border: groove 2px;"><p>Dear so and so, after reviewing your application I. . .</p><p>More of the same...</p><p>sincerely,</p><p>Important Dude</p></div>'); $oldWords = array('important', 'sincerely'); $newWords = array('arrogant', 'ya sure'); // function for oldWords function regex_oldWords_word_list(&$item1, $key) { $item1 = "/>([^<>]+)?\b$item1(tionally|istic|tion|ance|ence|less|ally|able|ness|ing|ity|ful|ant|est|ist|ic|al|ed|er|et|ly|y|s|d|'s|'d|'ve|'ll)?\b([^<>]+)?/"; } // function for newWords function format_newWords_results(&$item1, $key) { $item1 = ">$1<span style=\"color: red;\"><em> $item1$2</em></span>$3"; } // apply regex to oldWords array_walk($oldWords, 'regex_oldWords_word_list'); // apply formatting to newWords array_walk($newWords, 'format_newWords_results'); //HTML is not always as perfect as we want it $poo = array('/ /', '/>([a-zA-Z\']+)/', '/'/', '/;([a-zA-Z\']+)/', '/"([a-zA-Z\']+)/', '/([a-zA-Z\']+)</', '/\.\.+/', '/\. \.+/'); $unpoo = array(' ', '> $1', '\'', '; $1', '" $1', '$1 <', '. crap taco.', '. crap taco with cheese.'); //and maybe things will go back to normal sort of $repoo = array('/> /', '/; /', '/" /', '/ </'); $muck = array('> ', ';', '"',' <'); //before echo ($html); //I don't know what was happening on the free host but I had to keep stripping slashes //This is where the work is done anyway. $html = stripslashes(preg_replace($repoo , $muck , (ucwords(preg_replace($oldWords , $newWords , (preg_replace($poo , $unpoo , (stripslashes(strtolower(stripslashes($html))))))))))); //after echo ('<hr/> ' . $html); //now if only there were a way to keep it out of the area between //<style>here</style> and <script>here</script> and tell it that english isn't math. ?>
Kastor
source share