문제

How can I access these lines like a string ?

Its a get response from twitter, and im tring to use it.

stdClass Object
(
    [relationship] => stdClass Object
        (
            [source] => stdClass Object
                (
                    [id] => 2196933268
                    [id_str] => 2196933268
                    [screen_name] => damisleq
                    [following] => 1
                    [followed_by] => 
                    [notifications_enabled] => 
                    [can_dm] => 
                    [blocking] => 
                    [want_retweets] => 
                    [all_replies] => 
                    [marked_spam] => 
                )

            [target] => stdClass Object
                (
                    [id] => 175330071
                    [id_str] => 175330071
                    [screen_name] => sitetalkturkey
                    [following] => 
                    [followed_by] => 1
                )

        )

)
도움이 되었습니까?

해결책

Use the (string) method to cast a type in to the type string. For example:

$x = (string) $stdVar->relationship->source->screen_name;

var_dump($x); // will output string(n) "damisleq"

by the way, if you get the result from Twtter as JSON you can also use associative array function in json_decode. For example. $result = json_decode($string, true); the true states you want a array as result in stead of a stdObject.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top