异步传输PHP.卷曲.Ajax请求到站点,使用另一种编码


AJAX. PHP. CURL. Ajax request to site, with another encoding

我试图从另一个站点解析一个页面。为此,我使用cUrl

请求(将数据发送到脚本):

        $.ajax({
            url: 'wordstat/ajax?query='+query+'&page='+page+'&id='+id,
            success: function(data){
                alert(data);
            }
        });

这个脚本(wordstat/ajax),通过控制器向我的第二个站点请求:

控制器:

public function ajax()
{
    $this->model->auth();
    echo $this->model->parse_uri($_GET['page'],$_GET['query']);
}

型号:

public function parse_uri($url,$word)
{
    curl_setopt($this->curl, CURLOPT_URL, "http://wordstat/rating.php?url=".$url."&word=".$word."&gap=3");
    $html = mb_convert_encoding(str_replace("'n","",curl_exec($this->curl)), "utf-8", "windows-1251");
    preg_match('/<span style="font-size:14px" class=red>(.*)<'/span>/U',$html,$matches);
    return $matches;
}

如果我放入浏览器http://localhost/wordstat/ajax?page=page&url=url并打开此页面,那么她正确地返回了另一个站点的<span style="font-size:14px" class=red>的值

但当我通过Ajax请求执行时,它总是返回空的Array

我做错了什么?抱歉英语不好

您可以直接在浏览器中使用

wordstat/ajax?page=page&url=url

但是ajax使用

wordstat/ajax?query='+query+'&page='+page+'&id='+id

也许不同的论点会给你不同的结果。

问题已解决

    $url = str_replace(" ","",$url);
    $word = str_replace(" ","",$word);
    curl_setopt($this->curl, CURLOPT_URL, "http://parser/rating.php?url=".$url."&word=".$word."&gap=3");
    $html = str_replace("'n","",curl_exec($this->curl));
    preg_match('/<span style="font-size:14px" class=red>(.*)<'/span>/U',$html,$matches);
    return $matches;

感谢anyoune,他试图帮助