Curl doesn't accept var with plus characters


I tried using the 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 = “$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);
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 name=“text” rows=“6” cols=“50”>

<?php print str_replace("+"," ",$_GET['text']); ?>


<----------select name=“langfrom”>
<----------option value=“en”>English
option value=“fr”>French
<----------select name=“langto”>
<----------option value=“en”>English
<----------option value=“fr”>French
<----------INPUT TYPE=“submit” VALUE=“Translate”>

Why not convert the spaces to 's?

Check out Gordaen’s Knowledge, the blog, and the MR2 page.

How could this help?
The problem is that when the user submits the spaces in the textarea are converted to plus characters and even after I convert them to spaces or to another character, curl ignores the variable. If I type in the textarea plus characters instead of spaces then they are converted to + which curl has no problem with.

Hmm, that was supposed to be a percent 20, but apparently this board decodes those. I guess I should have previewed.

Are you in control of the data coming from the form directly? If so, have you tried urlencode?

Check out Gordaen’s Knowledge, the blog, and the MR2 page.

When the user uses the translation service from FoxLingo (my firefox extension) then I am in control of the data, so I can easily send it with underscores and then there is no problem.
But when the user enters text into the textarea and submits then the text to gets sent to the query string with the plus characters that curl can’t read (even after I replace them).

Can you do urlencode on the sending form and then urldencode it on the other side? That will replace your + signs with hex.

Angela Gann
CrimsonDryad Web Design Services
Web Design, Custom Software Development

Thank you so much!!!
You saved me so much time. : )