How can I script this in a better way?
// Tweets
$twitter_username_string = "aasampat OR ashwinsampat OR somemore";
$twitter_number_of_tweets = 1;
$twitter_hashtags = "ashwinsampat+OR+franq2+OR+franq2.net";
// Instantiate a Twitter object which will scan Twitter depending on the parameters
$twitter = new Twitter($twitter_username_string, $twitter_number_of_tweets, $twitter_hashtags);
$tweets = $twitter->getTweets();
foreach ( $tweets as $tweet )
{
$tweetoutput = "<p>".$tweet->title." <em>Tweeted by <a href=".$tweet->permalink." target=_blank title=@".$tweet->user.">".$tweet->author."</em></a></p>";
}
$twitter_username_string = "aasampat OR ashwinsampat OR somemore";
$twitter_number_of_tweets = 2;
$twitter_hashtags = "ashwinsampat+OR+franq2+OR+franq2.net";
// Instantiate a Twitter object which will scan Twitter depending on the parameters
$twitter = new Twitter($twitter_username_string, $twitter_number_of_tweets, $twitter_hashtags);
$tweets = $twitter->getTweets();
foreach ( $tweets as $tweet )
{
$tweetoutput_secondline = "<p>".$tweet->title." <em>Tweeted by <a href=".$tweet->permalink." target=_blank title=@".$tweet->user.">".$tweet->author."</em></a></p>";
}
$myFile = "export_file_twitter_output";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $tweetoutput;
fwrite($fh, $stringData);
fclose($fh);
$filename = 'export_file_twitter_output';
$somecontent = "$tweetoutput_secondline";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
} else {
echo "The file $filename is not writable";
}