0

I have in a string an url which has unfortunately foreign characters . when I send them to curl_setopt ($go, CURLOPT_URL, $url) nothing happens, the command is not running. On the other hand when I use my chrome browser and copy the link location , which has foreign characters and paste them on the browser suddendly the the foreign chars are encoded to something like %20%D5%F0%EF%EB%EF%E3%E9%F3%F4%DD%F2 , I know that %20 stands for space .. and this converted string works with curl command Have used urlencode , iconv but haven't find the right method yet. the result doesnt match with the pasted one. Is there any function which does it? The chars are greek. Thanks a lot

0

2 Answers 2

1

I had the same problem.

When I was running the curl functions and the url contained only English characters everything was fine.

But when the url contained Greek characters then it didn't work and returned "HTTP Error 400. The request URL is invalid."

I searched a lot and the solution was to use the following command:

$url = mb_convert_encoding($url, "iso-8859-7", "UTF-8");

Below is a full example:

$ch = curl_init(); 
$url = mb_convert_encoding($url, "iso-8859-7", "UTF-8");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_HEADER, true);
$page = curl_exec($ch); 
curl_close($ch);
Sign up to request clarification or add additional context in comments.

Comments

0

What is original encoding of that webpage? Can you give us url and part of source code?

Try to convert string to requested character encoding

$response = html_entity_decode(htmlentities(curl_exec($ch)), ENT_COMPAT, 'UTF-8'); 
$response = iconv('windows-1253','utf-8',$response );  

3 Comments

oktabit.gr/… is the encoded url , and if I;m right the encoding is windows-1253 I do not know if you are familiar with greek, but you can click on the left column, where all categories all listed , click on any , probably you can find listed 'server' and every vertical menu of this category has the original url with some greek chars in.
$timeout = 5; $chw = curl_init(); $cookies = $suppliers.'.txt'; curl_setopt($chw, CURLOPT_POSTFIELDS, $postData); curl_setopt($chw, CURLOPT_URL, $urls); curl_setopt($chw, CURLOPT_HEADER, 0); curl_setopt($chw, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($chw, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($chw, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"); curl_setOpt($chw, CURLOPT_POST, false); curl_setopt($chw, CURLOPT_COOKIEFILE, $cookies);
code is not working . still getting foreign greek chars in he html url string and not the encoded ones.. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.