-2

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
                )

        )

)
Alireza Fallah
  • 4,609
  • 3
  • 31
  • 57
Emre Y
  • 51
  • 1
  • 7

1 Answers1

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.

Pakspul
  • 648
  • 5
  • 17
  • Yes output is = string(11) "damisleq" How can i get only damisleq ? – Emre Y Jan 17 '14 at 15:15
  • Please learn about the different methods in PHP for outputting data: `var_dump()` can be replaced with (for example `print()`) or you could `echo` the value.... outputting text to a display really is fundamental PHP 101 day 1 type stuff – Mark Baker Jan 17 '14 at 15:18