Tycho01 Posted January 30, 2010 Share Posted January 30, 2010 I'm quite new to PHP, and am not even sure if it's even the right way to go about solving this. I tried searching around for a little bit, but I'm really not sure what exactly to look for. The code I currently have is as follows: <html><body> <form action="tycho.php" method="post"> Text: <textarea id="text" name="text" class="element textarea medium">text</textarea> Dictionary: <textarea id="dict" name="dict" class="element textarea medium">dict</textarea> <input type="submit" /></form> <?php $text=$_POST["text"]; $dictionary=$_POST["dict"]; //Read text areas $patterns = array(); $replacements = array(); for ($i=0; !feof($dictionary); $i++) { $line = fgetcsv($dictionary); $patterns[i] = $line[0]; $replacements[i] = $line[1]; } //Read dictionary and split it up into arrays $patterns and $replacements for ($i=0; $i<count($patterns); $i++) { $text = preg_replace($patterns[i], $replacements[i], $text); } ... //Replace patterns with replacements in text and write it to text area text ?></body></html> .. where 'tycho.php' refers to the script itself, and the '...' line being the part I didn't figure out yet. What I'm trying to do here is to allow the user to translate (= mass-replace) the content of one text area ('text') using the csv-styled contents of a second text area ('dictionary'). Example of what the input/output should look like: Input text: cats are animals. Input dictionary: cats,katten animals,dieren Output text: katten are dieren. (This example makes no sense of course -- in reality I'd like to use the script to translate terminology from games, as regular online translators already exist.) Anyway, I think I've managed to make the script alter the variable $text as it's supposed to, but now how would I get this written to the/a text area again after pressing submit? A friend of mine proposed not putting anything for the '...' line, but instead replacing the contents of the first text area at the top ('text') with <?php print($text); ?>. However, this just seems to result in an infinite loop... I'm probably going about this the wrong way... any ideas? Link to comment https://forums.phpfreaks.com/topic/190355-translation-script/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.