0

I've been following the directions in this answer but there seems to be a missing step at the end. - https://stackoverflow.com/a/17057693/348174

I have the PHP file working correctly up until the last step - http://joehamilton.info/hrh/tweet.php

But I have no idea how to get the actual tweet out of that crazy string in to my actual website which is a separate html page.

Any advice would be appreciated.

Community
  • 1
  • 1
Joe Hamilton
  • 665
  • 2
  • 9
  • 19
  • I don't think you should have that `Array` part on the end. That's probably an artifact of PHP converting an array in your code to a string. – Alex W Feb 01 '14 at 13:07
  • @Joe Hamilton How do you generate that `crazy string`? Are you just printing the response from twitter API? – Jenson M John Feb 01 '14 at 13:43
  • Yeah I think that is what is happening @JensonMJohn... I followed these directions to get this far - http://stackoverflow.com/questions/17049821/setting-up-twitter-api-getting-the-last-few-tweets/17057693#17057693 – Joe Hamilton Feb 01 '14 at 13:54

2 Answers2

1

Store that so called 'crazy string' value into a php variable. That string actually is in json format. So convert that json string variable into PHP array & loop through array accordingly to obtain your results.

For eg.

<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
<?php


$str= file_get_contents("http://joehamilton.info/hrh/tweet.php"); //Provided json string available here!
$json_arr=json_decode($str,true);

echo "<pre>";
//print_r($json_arr);
echo "</pre>";

echo $json_arr[0]['text'];

?>
    </body>
</html>
Jenson M John
  • 5,499
  • 5
  • 30
  • 46
0

That crazy string is JSON. It is an array of objects. What you need to do is assign it to a JavaScript variable on your webpage. Then, using JavaScript, you can print out that information.

Example:

var tweetArray = echo crazy string here with PHP; // Make sure you follow it with ;

Then you can display the tweet using JavaScript, like this (to give you an idea):

document.body.innerHTML += "<h1>"+tweetArray[0].text+"</h1>";
Alex W
  • 37,233
  • 13
  • 109
  • 109
  • ok great. that seems like the right track. thank you! One more noob question though... I'm not sure how to echo the crazy string inside the javascript though.. I tried putting all the PHP code between the square brackets and it didn't work. I assume you leave the PHP code in a separate file and import it or something? – Joe Hamilton Feb 01 '14 at 13:22