<?php 


	$username = $_POST['username'];

	$url = "https://api.stocktwits.com/api/2/streams/user/".$username.".json";

	$ch = curl_init($url);
	$header = array();
	$header[] = 'Content-type: application/json';
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	$resultsj = curl_exec($ch);

	$typarray = (array)$resultsj;

	$resultArray = $typarray[0];
	$jsonResult = json_decode($resultArray);
	$jsonMsg = $jsonResult->messages;

	$resultingarray = array();

	foreach ($jsonMsg as $json_msg) {
		# code...

		$bodyMsg = $json_msg->body;

		$created_at = $json_msg->created_at;

		$userData = $json_msg->user;

		$userName = $userData->username;

		$Name = $userData->name;

		$image = $userData->avatar_url;

		$swtarray = array('name'=>$Name, 'username'=>$userName, 'image'=>$image,'body'=>$bodyMsg,'created'=>$created_at);

		$swtarray = json_encode($swtarray);

		array_push($resultingarray, $swtarray);

	}


print_r(json_encode($resultingarray));

?>