0

I want to get just the text of that last twitter post of a user. I found code that abstracts a users feed to the json format but How do I get the json vars to php vars? And in 'partucalar' the 'TEXT' var as seen below.

Here is the Script I am using to convert the twitter feed to json: LINK TO CODE HOWEVER, This is irrelevant to this question. I just need the output vars to become php vars. I was already down voted so I am giving more details.

Here is the json output:

{
    "tweets": [
        {
            "url": "http://twitter.com/cosmocatalano/status/343768531101417474",
            "text": "This is a test tweet. @ Sufferloft http://instagram.com/p/aWFnSJInU-/ ",
            "html": "This is a test tweet. @ Sufferloft <a href=\"http://t.co/XRaizXhwYz\" rel=\"nofollow\" dir=\"ltr\" data-expanded-url=\"http://instagram.com/p/aWFnSJInU-/\" class=\"twitter-timeline-link\" target=\"_blank\" title=\"http://instagram.com/p/aWFnSJInU-/\" ><span class=\"invisible\">http://</span><span class=\"js-display-url\">instagram.com/p/aWFnSJInU-/</span><span class=\"invisible\"></span><span class=\"tco-ellipsis\"><span class=\"invisible\">&nbsp;</span></span></a>",
            "date": "1370795779",
            "user": "/cosmocatalano",
            "id": "14503633",
            "img": "https://si0.twimg.com/profile_images/2225916199/image_normal.jpg",
            "name": "Cosmo Catalano",
            "rt": false,
            "card": {
                "href": "http://instagram.com/p/aWFnSJInU-/",
                "data-url": "http://distilleryimage2.ak.instagram.com/9d54f23ed12211e29fe522000a1f97ce_5.jpg",
                "data-resolved-url-large": "http://distilleryimage2.ak.instagram.com/9d54f23ed12211e29fe522000a1f97ce_7.jpg"
            }
        }
    ]
}

I want the TWEET text: // Example variable

$Tweet = jsondecode(text);
echo $Tweet;

1 Answer 1

1

Assuming the JSON string is stored in $jsonString.

$obj = json_decode($jsonString);
echo $obj->tweets[0]->text; // get the first tweet

Or loop over them if there's more than one tweet:

$obj = json_decode($jsonString);
foreach($obj->tweets as $tweet)
{
    echo $tweet->text;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome. That did it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.