dongnanman9093 2010-05-18 21:36
浏览 35
已采纳

如何通过PHP正确检索Flash网站的twitter xml

Am I using TwitterScript to retrieve Twitter data for inside a Flash site. Due to Twitter's crossdomain policy, I need to setup a php proxy... Firstly I made a simple one

<?php 
$url = $_GET['url'];
readfile($url);
?>

but I then get this error

URL file-access is disabled in the server configuration

which is only resolved by getting my host to turn fopen() on, which I don't want to do.

Then I found this

<?php

function get_content($url)
{
$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);

ob_start();

curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();

ob_end_clean();

return $string;    
}

#usage:
$url = $_GET['url'];
$content = get_content ($url);
var_dump ($content);
?>

which solves that problem but the data now is the correct XML but looks like:

string(39950) "<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
<status>
...
</statuses>"

How do I get the XML data out of that string?

  • 写回答

1条回答 默认 最新

  • duandu1377 2010-05-18 21:43
    关注

    Your problem is that you're using var_dump() when you want to output the result. Just use echo instead. Also you don't need output buffering to get the content of the site.

    Fixed Code

    <?php
    
    function get_content($url)
    {
    $ch = curl_init();
    
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    
    $string = curl_exec ($ch);
    curl_close ($ch);
    
    return $string;    
    }
    
    #usage:
    $url = $_GET['url'];
    $content = get_content ($url);
    echo $content;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式