Form that gets text from another site, Spaces in textarea
Posted: Sun Aug 20, 2006 1:20 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am creating a translation page that gets the text from a url which the query strings are past to.
When the user submits the form the text is sent to the querystring but the spaces are converted to plus-characters.
When I use curl with the $text string variable that contains plus-characters, it ignores the variable, and the url gets an empty query string.
Can I change the submit to create underscores instead of spaces?
If not then can I make curl support a string with plus-characters?
Or is there another way to do this?
Here is the translation page:
[url=http://www.concisefreeware.com/translate.php]http://www.concisefreeware.com/translate.php[/url]
Here is the code:Code: Select all
<?php function a2() { if ($_GET['theme'] == "w") print ("b"); else print ("w"); }
function a3() { if ($_GET['theme'] == "w") print ("w"); else print ("b"); }
function text() { print str_replace("_"," ",$_GET['text']); }
function data() {
$langfrom = $_GET['langfrom'];
$langto = $_GET['langto'];
$text = str_replace("_","%20",$_GET['text']);
$url = "http://www.worldlingo.com/S1889.1/api?wl_data=$text;&wl_srclang=$langfrom;&wl_trglang=$langto;&wl_password=secret";
$curl_handle = curl_init($url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$content = "";
$content = curl_exec($curl_handle);
curl_close($curl_handle);
$content = str_replace("0","",$content);
switch ($langfrom) {
case "en": if ($langto == en) $content = ""; break;
case "ar": if ($langto == ar) $content = ""; break;
case "zh_CN": if ($langto == zh_CN) $content = ""; break;
case "zh_TW": if ($langto == zh_TW) $content = ""; break;
case "nl": if ($langto == nl) $content = ""; break;
case "fr": if ($langto == fr) $content = ""; break;
case "de": if ($langto == de) $content = ""; break;
case "el": if ($langto == el) $content = ""; break;
case "ja": if ($langto == ja) $content = ""; break;
case "ko": if ($langto == ko) $content = ""; break;
case "pt": if ($langto == pt) $content = ""; break;
case "ru": if ($langto == ru) $content = ""; break;
case "es": if ($langto == es) $content = ""; break;
case "sv": if ($langto == sv) $content = ""; break;
}
print $content;
}
function check() {
$langfrom = $_GET['langfrom'];
$langto = $_GET['langto'];
$content = "";
switch ($langfrom) {
case "en": if ($langto == en) $content = "Please select two different languages.<br><br>"; break;
case "ar": if ($langto == ar) $content = "Please select two different languages.<br><br>"; break;
case "zh_CN": if ($langto == zh_CN) $content = "Please select two different languages.<br><br>"; break;
case "zh_TW": if ($langto == zh_TW) $content = "Please select two different languages.<br><br>"; break;
case "nl": if ($langto == nl) $content = "Please select two different languages.<br><br>"; break;
case "fr": if ($langto == fr) $content = "Please select two different languages.<br><br>"; break;
case "de": if ($langto == de) $content = "Please select two different languages.<br><br>"; break;
case "el": if ($langto == el) $content = "Please select two different languages.<br><br>"; break;
case "ja": if ($langto == ja) $content = "Please select two different languages.<br><br>"; break;
case "ko": if ($langto == ko) $content = "Please select two different languages.<br><br>"; break;
case "pt": if ($langto == pt) $content = "Please select two different languages.<br><br>"; break;
case "ru": if ($langto == ru) $content = "Please select two different languages.<br><br>"; break;
case "es": if ($langto == es) $content = "Please select two different languages.<br><br>"; break;
case "sv": if ($langto == sv) $content = "Please select two different languages.<br><br>"; break;
}
print $content;
}
function selectFrom($lang) {
$langfrom = $_GET['langfrom'];
if ($lang == $langfrom) print "selected=\"selected\"";
}
function selectTo($lang) {
$langto = $_GET['langto'];
if ($lang == $langto) print "selected=\"selected\"";
}
?>
<b><big><? check(); ?></big></b>
<FORM ACTION="translate.php" METHOD=GET>Translated Text:<br>
<textarea rows="6" cols="50">
<? data(); ?>
</textarea>
<br><br>
Original Text:<br>
<textarea name="text" rows="6" cols="50">
<? text(); ?>
</textarea><br><br>
<select name="langfrom">
<option value="en" <? selectFrom("en"); ?>>English
<option value="ar" <? selectFrom("ar"); ?>>Arabic
<option value="zh_TW" <? selectFrom("zh_TW"); ?>>Chinese Simplified
<option value="zh_CN" <? selectFrom("zh_CN"); ?>>Chinese Traditional
<option value="nl" <? selectFrom("nl"); ?>>Dutch
<option value="fr" <? selectFrom("fr"); ?>>French
<option value="de" <? selectFrom("de"); ?>>German
<option value="el" <? selectFrom("el"); ?>>Greek
<option value="it" <? selectFrom("it"); ?>>Italian
<option value="ja" <? selectFrom("ja"); ?>>Japanese
<option value="ko" <? selectFrom("ko"); ?>>Korean
<option value="pt" <? selectFrom("pt"); ?>>Portuguese
<option value="ru" <? selectFrom("ru"); ?>>Russian
<option value="es" <? selectFrom("es"); ?>>Spanish
<option value="sv" <? selectFrom("sv"); ?>>Swedish
</select>
to
<select name="langto">
<option value="en" <? selectTo("en"); ?>>English
<option value="ar" <? selectTo("ar"); ?>>Arabic
<option value="zh_TW" <? selectTo("zh_TW"); ?>>Chinese Simplified
<option value="zh_CN" <? selectTo("zh_CN"); ?>>Chinese Traditional
<option value="nl" <? selectTo("nl"); ?>>Dutch
<option value="fr" <? selectTo("fr"); ?>>French
<option value="de" <? selectTo("de"); ?>>German
<option value="el" <? selectTo("el"); ?>>Greek
<option value="it" <? selectTo("it"); ?>>Italian
<option value="ja" <? selectTo("ja"); ?>>Japanese
<option value="ko" <? selectTo("ko"); ?>>Korean
<option value="pt" <? selectTo("pt"); ?>>Portuguese
<option value="ru" <? selectTo("ru"); ?>>Russian
<option value="es" <? selectTo("es"); ?>>Spanish
<option value="sv" <? selectTo("sv"); ?>>Swedish
</select>
<INPUT TYPE="submit" VALUE="Translate">
</FORM>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]