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;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA