Curl doesn't accept var with plus characters

software development

#1

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>


#2

Why not convert the spaces to 's?

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


#3

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.


#4

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.


#5

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).


#6

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
http://www.crimsondryad.com


#7

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