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 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?