观察网站日志发现的,本来是urlencode的汉字url,百度蜘蛛抓到确成了下面这样的:"GET /tag/\xe5\x8f\x8c\xe5\x9f\x8e\xe5\xa4\x9c\xe8\x89\xb2\xe7\x89\x88\xe5\xa4\xb4\xe5\x86\xac\xe5\xa4\xa9\xe7\x89\x88 HTTP/1.0" 200 2066 "-" "Baiduspider+(+http://www.baidu.com/search/spider.htm)"
用什么php函数能把这样的字符串恢复成汉字呢?
如果是urlencode(),那用urldecode()就行了,但这一串“\xe5\x8f\x8c\xe5\x9f\x8e\xe5\xa4”不像是urlencode()

解决方案 »

  1.   


    header("Content-Type:text/html;charset=utf-8");
    $str = "\xe5\x8f\x8c\xe5\x9f\x8e\xe5\xa4\x9c\xe8\x89\xb2\xe7\x89\x88\xe5\xa4\xb4\xe5\x86\xac\xe5\xa4\xa9\xe7\x89\x88";
    echo $str;
      

  2.   


    谢谢,那如果在mysql中查询$str该怎么办呢?
    现在查的$str内容是:“\xe5\x8f\x8c\xe5\x9f\x8e\xe5\xa4\x9c\xe8\x89\xb2\xe7\x89\x88\xe5\xa4\xb4\xe5\x86\xac\xe5\xa4\xa9\xe7\x89\x88”怎样才能让$str变成汉字在mysql中进行查询呢?
      

  3.   

    有什么办法能让百度抓到encode的中文url也能解决问题,页面编码和数据库编码都是utf-8的,其他搜索引擎都能抓到encode的中文url,但url却被baiduspider抓成了问题中的那样