doulangchao8934 2017-05-25 20:30
浏览 45
已采纳

PHP打印JSON数组在值的顶部显示单词“数组”

Have the following Array that functions perfectly on the site, but before the first output the word "Array" is printed.

I figure it has to be in the $json_object or $fbdata query but cannot isolate or eliminate it from showing.

<?php

$page_id = '{page_id_here}';
$access_token = '{access_token_here}';
//Get the JSON
$json_object = @file_get_contents('https://graph.facebook.com/' . $page_id . 
'/posts?fields=full_picture,link,message&limit=3&access_token=' . 
$access_token);
//Interpret data
$fbdata = json_decode($json_object);

foreach ($fbdata->data as $post )
{
    $posts .= '<div class="col-sm-4">';
        $posts .= '<div class="stay-connected-inner">';
            $posts .= '<div class="stay-connected-info">';
                $posts .= '<div class="stay-connected-left"><i class="fa fa-facebook"></i></div>';
                $posts .= '<div class="stay-connected-right">';
                    $posts .= '<h5>Title</h5>';
                    $posts .= '<p><a href="' . $post->link . '" target="_blank">' . $post->message . '</a></p>';
                $posts .= '</div>';
            $posts .= '</div>';
            $posts .= '<div class="stay-connected-fig">';
                $posts .= '<p><a href="' . $post->link . '" target="_blank"><img src="' . $post->full_picture . '"></a></p>';
            $posts .= '</div>';
        $posts .= '</div>';
    $posts .= '</div>';
}
//Display the posts
print_r ($posts)

?>
  • 写回答

2条回答 默认 最新

  • duanlinzhen7235 2017-05-25 20:49
    关注

    Figured it out. I changed my 'posts' variable to 'postst'. The word 'post' was being used in the URL and that seems to have confused the array in some way.

    Updated code:

    <?php
    
    $page_id = '{page_id_here}';
    $access_token = '{access_token_here}';
    //Get the JSON
    $json_object = @file_get_contents('https://graph.facebook.com/' . $page_id . 
    '/posts?fields=full_picture,link,message&limit=3&access_token=' . 
    $access_token);
    //Interpret data
    $fbdata = json_decode($json_object);
    
    foreach ($fbdata->data as $post )
    {
    $postst .= '<div class="col-sm-4">';
    $postst .= '<div class="stay-connected-inner">';
    $postst .= '<div class="stay-connected-info">';
    $postst .= '<div class="stay-connected-left"><i class="fa fa-facebook"></i></div>';
    $postst .= '<div class="stay-connected-right">';
    $postst .= '<h5>Title</h5>';
    $postst .= '<p><a href="' . $post->link . '" target="_blank">' . $post->message . '</a></p>';
    $postst .= '</div>';
    $postst .= '</div>';
    $postst .= '<div class="stay-connected-fig">';
    $postst .= '<p><a href="' . $post->link . '" target="_blank"><img src="' . $post->full_picture . '"></a></p>';
    $postst .= '</div>';
    $postst .= '</div>';
    $postst .= '</div>';
    }
    //Display the posts
    print_r ($postst);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog