Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery在php cURL中搜索 函数curl\u下载($Url){ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$URL); curl_setopt($ch,CURLOPT_REFERER,”http://www.example.org/yay.htm"); curl_setopt($ch,CURLOPT_USERAGENT,“MozillaXYZ/1.0”); curl_setopt($ch,CURLOPT_头,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_超时,10); $output=curl\u exec($ch); 卷曲关闭($ch); 返回$output; } $curl=curl\u下载http://www.example.com'); $(函数(){ var myhtml=“”; });_Javascript_Php_Jquery_Curl - Fatal编程技术网

Javascript 使用jquery在php cURL中搜索 函数curl\u下载($Url){ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$URL); curl_setopt($ch,CURLOPT_REFERER,”http://www.example.org/yay.htm"); curl_setopt($ch,CURLOPT_USERAGENT,“MozillaXYZ/1.0”); curl_setopt($ch,CURLOPT_头,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_超时,10); $output=curl\u exec($ch); 卷曲关闭($ch); 返回$output; } $curl=curl\u下载http://www.example.com'); $(函数(){ var myhtml=“”; });

Javascript 使用jquery在php cURL中搜索 函数curl\u下载($Url){ $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$URL); curl_setopt($ch,CURLOPT_REFERER,”http://www.example.org/yay.htm"); curl_setopt($ch,CURLOPT_USERAGENT,“MozillaXYZ/1.0”); curl_setopt($ch,CURLOPT_头,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_超时,10); $output=curl\u exec($ch); 卷曲关闭($ch); 返回$output; } $curl=curl\u下载http://www.example.com'); $(函数(){ var myhtml=“”; });,javascript,php,jquery,curl,Javascript,Php,Jquery,Curl,这只是在我的网页上输出整个网站。而不是在Javascript中输入变量。 我想我会像处理标准HTML代码一样处理它 谢谢你。我不知道这是不是最好的办法。如果将整个html结果存储在js变量中,则javascript会由于多行和未设置双引号和单引号而引发错误。 您可以将该函数用作服务器端端点,并通过js中的ajax调用它。Jquery将处理html响应(避免引号冲突和新行),您可以在成功回调中将结果用作参数。您需要转义html。也许可以通过json\u encode运行它?这可能会为您处理所有的转

这只是在我的网页上输出整个网站。而不是在Javascript中输入变量。
我想我会像处理标准HTML代码一样处理它


谢谢你。我不知道这是不是最好的办法。如果将整个html结果存储在js变量中,则javascript会由于多行和未设置双引号和单引号而引发错误。
您可以将该函数用作服务器端端点,并通过js中的ajax调用它。Jquery将处理html响应(避免引号冲突和新行),您可以在成功回调中将结果用作参数。

您需要转义html。也许可以通过
json\u encode
运行它?这可能会为您处理所有的转义操作。

您能补充一下为什么要这样做吗?PHP可以解析和修改html(),因此最好在服务器端执行。因为在卷曲的html中有一个
,它标记了变量的结束。对卷曲变量运行Ajax调用?您可以详细说明吗?创建一个路由或另一个端点(我不知道您的程序的确切结构,但它也可能是同一个页面),然后通过ajax调用该端点
function curl_download($Url){
     $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

$curl = curl_download('http://www.example.com');

<script>
    $(function() {
        var myhtml = "<?=$curl;?>";
    });
</script>