php curl, getting bad characters

I am trying to gather data from a french website
using curl

I am getting
Complément téléobjectif


but the site says
Complément téléobjectif


LVL 1
rgb192Asked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
It's easy enough to try.  I never send the Content-type header - I let my server figure it out for me.
0
 
printnix63Commented:
You will have to URL-Encode them, these are double byte characters and URL/curl will only get plain ASCII. or if it is a POST request, request data binary.

From the curl Manual:
-d/--data <data>
(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a
browser does when a user has filled in an HTML form and presses the submit button. This will
cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded.
Compare to -F/--form.
-d/--data is the same as --data-ascii. To post data purely binary, you should instead use the --databinary
option. To URL-encode the value of a form field you may use --data-urlencode.
If any of these options is used more than once on the same command line, the data pieces specified
will be merged together with a separating &-symbol. Thus, using ’-d name=daniel -d skill=lousy’
would generate a post chunk that looks like ’name=daniel&skill=lousy’.
If you start the data with the letter @, the rest should be a file name to read the data from, or - if
you want curl to read the data from stdin. The contents of the file must already be URL-encoded.
Multiple files can also be specified. Posting data from a file named ’foobar’ would thus be done
with --data @foobar.
--data-binary <data>
(HTTP) This posts data exactly as specified with no extra processing whatsoever.
If you start the data with the letter @, the rest should be a filename. Data is posted in a similar
manner as --data-ascii does, except that newlines are preserved and conversions are never done.
If this option is used several times, the ones following the first will append data as described in
-d/--data.
--data-urlencode <data>
(HTTP) This posts data, similar to the other --data options with the exception that this performs
URL-encoding. (Added in 7.18.0)

Maybe you'll have to check on the php side for the implementation.
The letter encoding is definitly not what curl did expect.
0
 
rgb192Author Commented:

so what should I change this line to
header("Content-type: text/plain");
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Ray PaseurCommented:
What is the URL of the web site?  I may be able to show you how to retrieve the letters correctly.  I do not think that the accented characters are double-byte.
0
 
rgb192Author Commented:
0
 
Ray PaseurCommented:
CURL retrieves the data correctly, and I find things like Périphériques et Stockage in the text.  

Are you telling the browser that this is UTF-8?  Because Amazon is using this character set:
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);

// A FUNCTION TO RUN A CURL-GET CLIENT CALL TO A FOREIGN SERVER
function my_curl($url, $timeout=2, $error_report=FALSE)
{
    $curl = curl_init();

    // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
    $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );

    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);

    // ON FAILURE HANDLE ERROR MESSAGE
    if ($htm === FALSE)
    {
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN XML / HTML STRING
    curl_close($curl);
    return $htm;
}




// USAGE EXAMPLE - PUT YOUR FAVORITE URL HERE
$url = "http://www.amazon.fr/gp/product/B000V9D5LG";
$htm = my_curl($url, 5, TRUE);
if (!$htm) die("NO $url");


// SHOW WHAT WE GOT
echo "<pre>";
$htm = preg_replace('/ +/', ' ', $htm);
$htm = preg_replace('/\n+/', PHP_EOL, $htm);
echo htmlentities($htm);

Open in new window

0
 
rgb192Author Commented:
so if I change this line in my script from
header("Content-type: text/plain");

to

header("Content-type: charset=iso-8859-1");


it may work
0
 
rgb192Author Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.