【问题标题】:how to load another site content using php curl into a div in my site如何使用 php curl 将另一个网站内容加载到我网站的 div 中
【发布时间】:2013-09-29 18:14:48
【问题描述】:

我已经尝试过这种方式(根据“jerjer”的选择答案)但未能加载内容..

Load external site's content

render.php

<?php
    $url = 'http://apps.irs.gov/app/withholdingcalculator/index.jsp';
    $htm = file_get_contents($url);
    echo $htm;
?>

common.js

$(document).ready(function(){
    $('#divId').load('render.php');
});

index.html

<html>
<head>
    <title>Home</title>
    <link rel="stylesheet" href="css/style.css" type="text/css">
    <script src="js/jquery.js"></script>
    <script src="js/common.js"></script>
</head> 
<body>
    <div id="divId"></div>
</body>
</html>

有什么帮助吗?提前谢谢...

【问题讨论】:

  • iframe。框架。顿顿顿
  • 这段代码没有错误。 php 脚本正确返回外部网站的内容? (没有错误?好路径?)尝试直接在浏览器中打开render.php。
  • 为什么要使用AJAX来加载render.php?为什么不在索引中使用 php? (所以 index.php),只包括 render.php 那里。
  • 我必须根据我的需要修改渲染的内容...意味着我需要扣除一些内容..
  • 确保您的服务器允许 PHP 中的 cURL

标签: javascript php jquery curl


【解决方案1】:

使用此代码。确保你安装了 curl 扩展。

 $url = 'http://apps.irs.gov/app/withholdingcalculator/index.jsp';
 $htm = getCurlData($url);
 echo $htm;

function getCurlData($url)
{
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     $contents = curl_exec($ch);
     curl_close($ch);
     return $contents;
}

【讨论】:

    猜你喜欢
    • 2020-10-18
    • 2015-01-07
    • 2022-11-04
    • 2013-04-02
    • 2015-06-07
    • 1970-01-01
    • 2014-02-05
    • 2010-11-17
    • 1970-01-01
    相关资源
    最近更新 更多