php-general Digest 7 Aug 2011 03:50:52 -0000 Issue 7432

Topics (messages 314395 through 314398):

Unanticipated characters returned from multidimensional array
        314395 by: David Green
        314396 by: Shawn McKenzie

Re: testing
        314397 by: Judson Vaughn

Intentionally generate an "Internal Server Error"
        314398 by: Ghodmode

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
On 08/06/2011 08:09 AM, David Green wrote:
> 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>";
>     }
> 
> }

I haven't look through it long enough to find out about the characters,
but try this:

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


-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message --- Regardless, I am the beneficiary of someone's good work all these years and I, for one, appreciate it.

Jud



On 8/5/11 4:45 AM, David Robley wrote:
Daniel Brown wrote:

On Thu, Aug 4, 2011 at 10:39, Jim Giner<jim.gi...@albanyhandball.com>
wrote:
Mailing list, newsgroup, either one - something's changed in the last
week or so to interrupt the smooth (or semi-smooth) functioning of it.
The only messages I'm seeing currently are the ones in this single topic.
  Why is that???
     Actually, we haven't changed anything at all.  It's always been
temperamental, but it's always just been a small additional offering.
As Ash said, this is a mailing list, not a newsgroup.  The fact that
we offer a newsgroup interface at all is by all means eligible for
discontinuation, since only about six people use it in any given year.

/me wonders who the other five are :-)


Cheers

--- End Message ---
--- Begin Message ---
I'd like to use PHP to intentionally generate an "Error 500 Internal
Server Error".

Here's the problem.  My site has this error intermittently and I'd
like to monitor the error log to figure out the problem.
Unfortunately, I don't get to see the actual Apache error log and my
hosting provider's error reporting system isn't working.  Customer
support just sends me canned responses stating that everything's fine
and they can't reproduce the error, so I'd like to create a
reproducible internal server error so that they can see that it's not
showing up in the error log.

I know that I can mess up something in the .htaccess file, but that
would break the whole site.  I don't want to do that.

I know I could use header("HTTP/1.1 500 Internal Server Error"), but
that means I would also have to provide the content of the Error 500
page.  I want to kick off they're internal server error page.  They
don't give me to option to create one of my own.

I'm using GoDaddy.

Can someone suggest some invalid PHP code that should generate an
internal server error?

Thank you.

--
Ghodmode
http://www.ghodmode.com/blog

--- End Message ---

Reply via email to