Unanticipated characters returned from multidimensional array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hullo list

Like so many of those asking questions I'm new to PHP (in fact, new to
programming altogether - I'm a medical doctor in my "other" life).  Some of
what I show below is very likely redundant, so any pointers (beyond the
question asked) would be most welcome

I'm really struggling in the use of multidimensional arrays:

1) I retrieve my timeline from the twitter api and put the json returned
into an array:

require 'tmhOAuth.php';
require 'tmhUtilities.php';

$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => 'X',
  'consumer_secret' => 'X',
  'user_token'      => 'X',
  'user_secret'     => 'X',
));

$code = $tmhOAuth->request('GET', $tmhOAuth->url('1/statuses/home_timeline',
'json'));

$tableNews=json_decode($tmhOAuth->response['response'],true);

2) I then try to work with some elements of the returned data (just two for
now, but I ultimately want to display 3 or 4 of them in a table):

foreach($tableNews as $headline => $text){
    $new_text = $text['text'];
    echo "<br>";
    echo "$new_text";
    foreach ($text as $soucre => $description){
        $new_description = $description['name'];
        echo "<pre>";
        echo "$new_description";
        echo "</pre>";
    }

}

3) Then, because I was getting some unexpected characters in that, I print
the whole array:

echo '<pre>';
print_r($tableNews);
echo '</pre>';

A sample of what I get back looks like this in the browser:

Tutu slams Miyeni column [url removed - list spam filter didn't like!]

9

T

S

w

Eyewitness News


Libyan rebels report town under siege [url removed]

9

L

S

<

SA Breaking News

And the corresponding output for the whole array is:

Array
(
    [0] => Array
        (
            [retweet_count] => 0
            [possibly_sensitive] =>
            [geo] =>
            [coordinates] =>
            [in_reply_to_status_id] =>
            [id_str] => 99811704753496065
            [text] => Tutu slams Miyeni column [url removed]
            [favorited] =>
            [in_reply_to_status_id_str] =>
            [created_at] => Sat Aug 06 11:58:59 +0000 2011
            [in_reply_to_screen_name] =>
            [in_reply_to_user_id] =>
            [in_reply_to_user_id_str] =>
            [contributors] =>
            [retweeted] =>
            [source] => web
            [place] =>
            [id] => 9.98117047535E+16
            [user] => Array
                (
                    [friends_count] => 4502
                    [protected] =>
                    [profile_image_url_https] => [url removed]
                    [screen_name] => ewnupdates
                    [default_profile_image] =>
                    [statuses_count] => 40956
                    [profile_text_color] => 333333
                    [location] => South Africa
                    [name] => Eyewitness News
                    [following] => 1
                    [favourites_count] => 1
                    [profile_sidebar_fill_color] => D2D7DC
                    [id_str] => 20433284
                    [is_translator] =>
                    [profile_background_tile] =>
                    [utc_offset] => 7200
                    [url] => http://www.ewn.co.za
                    [follow_request_sent] =>
                    [description] => - Eyewitness News. In touch. In
tune. Independent.
                    [verified] =>
                    [created_at] => Mon Feb 09 13:03:22 +0000 2009
                    [profile_link_color] => B40000
                    [notifications] =>
                    [profile_sidebar_border_color] => 686C66
                    [default_profile] =>
                    [time_zone] => Pretoria
                    [listed_count] => 439
                    [lang] => en
                    [profile_use_background_image] => 1
                    [show_all_inline_media] =>
                    [contributors_enabled] =>
                    [geo_enabled] =>
                    [profile_background_color] => FBFCFC
                    [followers_count] => 15318
                    [profile_image_url] => [url removed]
                    [id] => 20433284
                    [profile_background_image_url_https] => [url removed]
                    [profile_background_image_url] => [url removed]
                )

            [truncated] =>
        )

    [1] => Array
        (
            [retweet_count] => 0
            [possibly_sensitive] =>
            [geo] =>
            [coordinates] =>
            [in_reply_to_status_id] =>
            [id_str] => 99811086940913664
            [text] => Libyan rebels report town under siege [url removed]
            [favorited] =>
            [in_reply_to_status_id_str] =>
            [created_at] => Sat Aug 06 11:56:32 +0000 2011
            [in_reply_to_screen_name] =>
            [in_reply_to_user_id] =>
            [in_reply_to_user_id_str] =>
            [contributors] =>
            [retweeted] =>
            [source] => [url removed]
            [place] =>
            [id] => 9.98110869409E+16
            [user] => Array
                (
                    [protected] =>
                    [screen_name] => sabreakingnews
                    [is_translator] =>
                    [profile_text_color] => 666666
                    [location] => South Africa
                    [name] => SA Breaking News
                    [follow_request_sent] =>
                    [following] =>
                    [favourites_count] => 0
                    [profile_sidebar_fill_color] => 252429
                    [id_str] => 34908698
                    [profile_background_tile] =>
                    [utc_offset] => -10800
                    [url] => [url removed]
                    [description] => All the latest breaking news from
across South Africa in one stream.
                    [verified] =>
                    [created_at] => Fri Apr 24 12:09:12 +0000 2009
                    [profile_link_color] => 2FC2EF
                    [listed_count] => 327
                    [notifications] =>
                    [profile_sidebar_border_color] => 181A1E
                    [default_profile] =>
                    [show_all_inline_media] =>
                    [contributors_enabled] =>
                    [geo_enabled] => 1
                    [time_zone] => Greenland
                    [lang] => en
                    [profile_use_background_image] => 1
                    [profile_background_image_url_https] => [url removed]
                    [friends_count] => 86
                    [profile_background_color] => 1A1B1F
                    [followers_count] => 9502
                    [profile_image_url_https] => [url removed]
                    [profile_image_url] => [url removed]
                    [id] => 34908698
                    [default_profile_image] =>
                    [statuses_count] => 35519
                    [profile_background_image_url] => [url removed]
                )

            [truncated] =>
        )

I really have no idea at all where the 9, T, S, and W come from? Or how to
stop them from appearing.
And, of course, the source has a lot of <pre>,</pre>'s in it!

Kind regards
David

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux