[PHP] curl and UTF-8

2002-08-26 Thread Merijn van den Kroonenberg

Hello List,

I have a problem with the php CURL module and UTF-8 data.
My php script uses curl to do a post to a perl/cgi script. This perl script
returns UTF-8 encoded XML. The perl script returns utf-8, i have verified
that using the webserver logfiles, but the data that i receive in $result
(see below) is decoded to ISO-8859-1.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec ($ch);//  UTF compatible?
curl_close ($ch);

Anyone an idea how i can get curl to return me UTF-8 data?

Thank you,

Merijn van den Kroonenberg



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] curl and UTF-8, follow up

2002-08-26 Thread Merijn van den Kroonenberg

I did some further testing, and i found that this behaviour is not
consistent. Actually i am pretty puzzled about this.

When i wrote the message below is was testing with a xml document that
contained only the following multi byte utf chacracter:
\303\253(octal utf8) (LATIN SMALL LETTER E WITH DIAERESIS)
The output from CURL got automatically decoded to latin1.

Then after i wrote the message i tested with another xml document that
contained the following multi byte utf character:
\342\202\254 (octal utf8) (EURO SIGN)
I was suprised to see that the output was now correct UTF-8.

Now i modified the first document and inserted the EURO SIGN in this
document. When i process this document again, the CURL output is UTF-8. So
it seems the output of CURL depends on what it detects on its imput, and it
will try to convert the data to latin1 if possible??

Does anyone know how i can disable this behaviour? For me, CURL should not
do any encoding of my data.

Greetings,
  Merijn van den Kroonenberg


- Original Message -
From: "Merijn van den Kroonenberg" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 26, 2002 2:36 PM
Subject: [PHP] curl and UTF-8


> Hello List,
>
> I have a problem with the php CURL module and UTF-8 data.
> My php script uses curl to do a post to a perl/cgi script. This perl
script
> returns UTF-8 encoded XML. The perl script returns utf-8, i have verified
> that using the webserver logfiles, but the data that i receive in $result
> (see below) is decoded to ISO-8859-1.
>
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL, $post_url);
> curl_setopt($ch, CURLOPT_HEADER, 0);
> curl_setopt($ch, CURLOPT_VERBOSE, 0);
> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
> $result = curl_exec ($ch);//  UTF compatible?
> curl_close ($ch);
>
> Anyone an idea how i can get curl to return me UTF-8 data?
>
> Thank you,
>
> Merijn van den Kroonenberg
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Curl request works on command line but not in script

2002-08-28 Thread Merijn van den Kroonenberg

Hi,

make sure you urlencode everything that is sent on the url, or as postvars.
$d2 =urlencode($d2);
and so on
then
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);

don't use the $testrequest, cause it has un-urlenoded values

I think that should do the trick.

Merijn van den Kroonenberg

e-factory bv
Tel.: +31 (0)475 - 340 975
Fax: +31 (0)475 - 320 351
Web: www.e-factory.nl


- Original Message -
From: "Joshua Alexander" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 28, 2002 6:13 AM
Subject: [PHP] Curl request works on command line but not in script


> Hi folks,
>
> I'm trying to send an XML request to a server to get its response
> back... I can get it to work on the command line (with passthru) but
> not with libcurl. I'm using libcurl 7.9.2 which may actually be
> different from the curl on the command line... the latter came with
> OS X, the former came from entropy.ch with the PHP package I
> installed. Of course my host is using 7.9.4 and the script doesn't
> work there either.
>
> I've tried it with both GET and POST... here are some setup variables.
>
> $testrequest = "$server?API=Rate&XML= PASSWORD=\"$password\">
ID=\"0\">EXPRESS2077020852100NoneREGULAR";
>
> $post['API']="Rate\n";
> $post['XML']= "' PASSWORD=\"$password\">
ID=\"0\">EXPRESS2077020852100NoneREGULAR'\n";
>
> # (I've tried it with the 's and without, with the \n's and without)
>
> $d1 = "API=Rate";
> $d2 = "XML=' PASSWORD=\"$password\">
ID=\"0\">EXPRESS2077020852100NoneREGULAR'";
>
> $ch = curl_init();
>
> # doesn't work, returns Error 400
> curl_setopt($ch, CURLOPT_URL, $testrequest);
>
> # also doesn't work, returns BAD REQUEST
> curl_setopt($ch, CURLOPT_URL, $server);
> curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
>
> # what DOES work
> passthru("curl -d " . $d1 . " -d " . $d2 . " $server");
>
>
> Any ideas?
>
> -Josh
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] preg_match

2002-08-28 Thread Merijn van den Kroonenberg

hi,

yes, you have to escape the '.' because it has a special meaning, it matches
on Any character (except newline maybe).
But you probably do not need a preg_match anyway.

Merijn van den Kroonenberg

e-factory bv
Tel.: +31 (0)475 - 340 975
Fax: +31 (0)475 - 320 351
Web: www.e-factory.nl


- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 28, 2002 9:39 AM
Subject: [PHP] preg_match


> hi all,
>
> i'm trying to create an script that cut's the text when a "." ( dot ) is
> found in one of the last words..
>
> i'm trying it with preg_match but it seems not to work.
>
> this is what i'm trying :
>
> if($i==15) {
>if(preg_match("/./",$text2[15])) {
>$text3 .= "($i $text2[15] )";
>break;
>}
> }
>
> could some one tell me what i'm doing wrong?
>
> thnx
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] curl and UTF-8, follow up

2002-08-28 Thread Merijn van den Kroonenberg

Hi,

This problem is solved now (thanks Wez Furlong). The problem was, that i had
the mbstring php module enabled (check with phpinfo). By default this module
encodes input data. After i added the following lines to the php.ini the
problem was solved:
mbstring.http_input = pass;
mbstring.http_output = pass;

bottomline, be carefull when activating this module, it might do more than
you expect ;-)

Merijn

- Original Message -
From: "Merijn van den Kroonenberg" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 26, 2002 4:10 PM
Subject: [PHP] curl and UTF-8, follow up


> I did some further testing, and i found that this behaviour is not
> consistent. Actually i am pretty puzzled about this.
>
> When i wrote the message below is was testing with a xml document that
> contained only the following multi byte utf chacracter:
> \303\253(octal utf8) (LATIN SMALL LETTER E WITH DIAERESIS)
> The output from CURL got automatically decoded to latin1.
>
> Then after i wrote the message i tested with another xml document that
> contained the following multi byte utf character:
> \342\202\254 (octal utf8) (EURO SIGN)
> I was suprised to see that the output was now correct UTF-8.
>
> Now i modified the first document and inserted the EURO SIGN in this
> document. When i process this document again, the CURL output is UTF-8. So
> it seems the output of CURL depends on what it detects on its imput, and
it
> will try to convert the data to latin1 if possible??
>
> Does anyone know how i can disable this behaviour? For me, CURL should not
> do any encoding of my data.
>
> Greetings,
>   Merijn van den Kroonenberg
>
>
> - Original Message -
> From: "Merijn van den Kroonenberg" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, August 26, 2002 2:36 PM
> Subject: [PHP] curl and UTF-8
>
>
> > Hello List,
> >
> > I have a problem with the php CURL module and UTF-8 data.
> > My php script uses curl to do a post to a perl/cgi script. This perl
> script
> > returns UTF-8 encoded XML. The perl script returns utf-8, i have
verified
> > that using the webserver logfiles, but the data that i receive in
$result
> > (see below) is decoded to ISO-8859-1.
> >
> > $ch = curl_init();
> > curl_setopt($ch, CURLOPT_URL, $post_url);
> > curl_setopt($ch, CURLOPT_HEADER, 0);
> > curl_setopt($ch, CURLOPT_VERBOSE, 0);
> > curl_setopt($ch, CURLOPT_POST, 1);
> > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> > curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
> > $result = curl_exec ($ch);//  UTF compatible?
> > curl_close ($ch);
> >
> > Anyone an idea how i can get curl to return me UTF-8 data?
> >
> > Thank you,
> >
> > Merijn van den Kroonenberg
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php