doudao7511 2014-08-06 04:46
浏览 88
已采纳

Php - url / string包含阿拉伯语字符

I am working on something that grabs 1 image from bing images.
For some reason file_get_contents did not work so I searched a bit and got the following method - which works great with English keywords:

$fp = fsockopen("www.bing.com", 80, $errn, $errs);
$ar = "عربي"; 
$out  = "GET /images/search?q=$ar HTTP/1.1
";
echo "$out";
echo "<Br><br>";
$out .= "Host: www.bing.com
";
$out .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0
";
$out .= "Connection: close
";
$out .= "
";

fwrite($fp, $out);

$response = "";
while ($line = fread($fp, 4096)) {
   $response .= $line;
} 
fclose($fp);


$response_body = substr($response, strpos($response, "

") + 4);
// or
list($response_headers, $response_body) = explode("

", $response, 2);

So if $ar contains english keyword(s), it works perfect. However, when I try and put in an arabic word - the results are convoluted - and doesn't match the results to bing image search.

Top of my php file I have :

<meta http-equiv='content-Type' content='text/html; charset=UTF-8'/>

Any help would greatly be appreciated. TIA

  • 写回答

2条回答 默认 最新

  • dspv70887 2014-08-06 05:03
    关注

    I know you said you tried urlencode() but this worked for me:

    $ar = urlencode("عربي");

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败