死简单的跨域php脚本

死简单的跨域php脚本,php,javascript,jquery,cross-domain,Php,Javascript,Jquery,Cross Domain,我正在寻找一个简单的脚本,在其中我可以做这样的事情 $.getScript('fetcher.php?url=' + escape('http://www.google.com') + '&callback=console.log'); 响应应该是一条非常长的线,看起来像这样: console.log({responseText: '<!doctype html><html><head><meta http-equiv="content-typ

我正在寻找一个简单的脚本,在其中我可以做这样的事情

$.getScript('fetcher.php?url=' + escape('http://www.google.com') + '&callback=console.log');
响应应该是一条非常长的线,看起来像这样:

console.log({responseText: '<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Google</title><script>windo...'})
console.log({responseText:'Googlewindo…'))
它不应该超过10行代码,而且它不可能不存在


我在XAMPP中使用php,我只是用它来构建一个数据库,所以我不需要包含任何花边(没有get vs post,没有包含数据),只要
file\u get\u contents
$\u get
。当然,我仍然希望对url进行编码

这个更新了吗

<?php
    // fetcher.php
    $url = $_GET['url'];
    $callback = $_GET['callback'];
    $read = file_get_contents($url);
    $read = addslashes(htmlspecialchars(str_replace("\n","\\n",$read)));
?>
<script>
    <?php echo $callback ?>({responseText: '<?php echo $read; ?>'});
</script>

({responseText:''});

fetcher.php

<?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $_GET['url']);
    echo curl_exec($ch);
    curl_close($ch);
?>

是否限制每行的字符数?如果没有,我可以写在一行:D@thaolt:一个可读的脚本怎么样,只是选项不太多这个链接很好地描述了这个问题:@SeanKinsey:我问这个问题是因为我认为这个问题已经存在,不想重新发明我想保留的轮子,
'\n'
(html中的换行符)变成
'\\n'
(在回答中)因此字符串中是一个换行符。另外,我希望能够使用转义URL。我还没有测试这个,您是否尝试过dakis的代码,我会测试它。我不介意,我没有curlok,我会尝试帮助您,str_replace(“\n”,“\\n”。。现在似乎运行不正常,但我不知道它是否适合您的需要
$.get("fetcher.php", {url: "http://www.google.com/"}, function(response) {
    console.log(response);
});