我如何通过一些在线工具执行此 PHP 脚本? (我什么都不知道)

How can I execute this PHP script via some online tool? (I know nothing)

我遇到了与这个较旧的 post 相同的问题: Facebook API: Get fans of / people who like a page

我的问题是关于最佳答案提供的代码:

See further below for updated code

我想知道如何以某种方式 运行 这段代码(当然,使用我自己的参数)。我查看了在线 PHP 脚本执行程序的一些选项,因为我不熟悉任何可用的 IDE 或类似的选项。更重要的是:我不知道有什么方法可以得到 运行 这个 PHP 脚本(假设它是有效的并且没有遗漏一些重要的设置)。

我希望有某种可用的控制台,然后我可以在执行结束时看到完整打印的结果数组。

我的(最简单的)选择是什么?我不想从头开始完全学习 PHP。我只是在寻找我链接到的 post 中描述的功能。

非常感谢任何能提供必要见解的人! :)

此致, 基尔留

编辑:

http://phpfiddle.org/ 似乎符合我的要求,但输出只是 "Array()"。我想打印它的所有值——我该如何实现? 我试图将执行行更改为:

print_r(array_values(fetch_fb_fans('ComputerHjælp', 5, 400000)));

虽然这不会改变结果。

编辑2: 我按照 phpfiddle 网站的规定进行了一些编辑,并将代码附在 php 标签中。我现在根本没有得到它出现的任何数据,因为现在打印 "nope" 而不是数组值。 Facebook API 的编码器访问有问题吗?

<?php
function fetch_fb_fans($fanpage_name, $no_of_retries = 10, $pause = 500000 /* 500ms */){
    $ret = array();
    // get page info from graph
    $fanpage_data = json_decode(file_get_contents('http://graph.facebook.com/' . $fanpage_name), true);
    if(empty($fanpage_data['id'])){
        // invalid fanpage name
        return $ret;
    }
    $matches = array();
    $url = 'http://www.facebook.com/plugins/fan.php?connections=100&id=' . $fanpage_data['id'];
    $context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0')));
    for($a = 0; $a < $no_of_retries; $a++){
        $like_html = file_get_contents($url, false, $context);
        preg_match_all('{href="https?://www\.facebook\.com/([a-zA-Z0-9._-]+)" data-jsid="anchor" target="_blank"}', $like_html, $matches);
        if(empty($matches[1])){
            // failed to fetch any fans - convert returning array, cause it might be not empty
            return array_keys($ret);
        }else{
            // merge profiles as array keys so they will stay unique
            $ret = array_merge($ret, array_flip($matches[1]));
        }
        // don't get banned as flooder
        usleep($pause);
    }
    return array_keys($ret);
}

$val = fetch_fb_fans('Komplett.dk', 5, 400000);

if(empty($val)){
    echo "nope";
}
foreach($val as $key => $value)
{
  echo $key." has the value". $value;
}

?>

事情就在这里,我知道有一个名为 "Komplett.dk" 的 Facebook 网站,但显然有些东西不起作用。该代码来自 2013 年 4 月。Facebook API 是否以某种方式更新,导致此代码无法按预期工作?

您可以使用以下在线 php 编译器

编译您的 php 代码

http://www.tutorialspoint.com/codingground.htm

http://phpfiddle.org/

以及 sql

http://sqlfiddle.com/