Curl doesn't accept var with plus characters
Posted by: YotamElal
Posted on: 2006-08-23 01:27:00
Hello,
I tried using the http://wiki.dreamhost.com/index.php/PHP_Magic_Quotes code, I am not sure if I did it correctly.
After playing around with it with no success I changed the cod back and decided to try to get help from you with my problem.
My problem is that curl is not excepting any plus characters in the variable and it doesn't accept the variable even after I remove the plus characters with str_replace.
Please see if you can help me, I've spent a lot of time trying to solve this.
My dreamhost is configured to use PHP 5.
Curl sends $text as an empty variable. If I try to print $text it prints without the pluses.
Here is the problematic code:
In the url $_GET['text'] equals word+word.
function data() {
$langfrom = $_GET['langfrom'];
$langto = $_GET['langto'];
$text = stripslashes($_GET['text']); // I tried also with plain $text = $_GET['text'];
$text = str_replace("+"," ",$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);
print $content;
}
Another way you can help me solve this problem is from a completley different approach.
When submitting a form with a textarea the spaces are automatically converted to the plus character. If this can be changed to replace spaces with an underscore or a + then the problem will be solved.
Here is the for code:
<----------FORM ACTION="translate.php" METHOD=GET>Translated Text:
<----------textarea rows="6" cols="50">
<? data(); ?>
<----------/textarea>
<----------textarea name="text" rows="6" cols="50">
<?php print str_replace("+"," ",$_GET['text']); ?>
<----------/textarea>
<----------select name="langfrom">
<----------option value="en">English
option value="fr">French
<----------/select>
<----------select name="langto">
<----------option value="en">English
<----------option value="fr">French
<----------/select>
<----------INPUT TYPE="submit" VALUE="Translate">
</----------FORM>