Hello,
I’ve been searching for some time and can’t figure out how to create an array with multiple variables. Anyways I’m trying to monitor Twitter and want to have a few keywords being scanned if something is mentioned. So, I’ve got a script that works fine but I cant figure out how to make it work with more than one keyword. The code is below, thanks for looking.
You can see my comment in the code, basically I want to have the below loop be able to look/find multiple items at the same time. I’m guessing there is a way just not sure how to.
Thanks.
[php]
<?php include_once('config.php'); $opts = array( 'http'=>array( 'method' => "POST", 'content' => 'track='.WORDS_TO_TRACK1, // Here is where I want to be able to have multiple keywords found, so for example have a WORDS_TO_TRACK2 ) ); $db = mysql_connect('localhost', 'username', 'password!'); mysql_select_db('database', $db); $context = stream_context_create($opts); while (1){ $instream = fopen('https://'.TWITTER_USERNAME.':'.TWITTER_PASSWORD.'@stream.twitter.com/1/statuses/filter.json','r' ,false, $context); while(! feof($instream)) { if(! ($line = stream_get_line($instream, 20000, "\n"))) { continue; }else{ $tweet = json_decode($line); //Clean the inputs before storing $id = mysql_real_escape_string($tweet->{'id'}); $text = mysql_real_escape_string($tweet->{'text'}); $screen_name = mysql_real_escape_string($tweet->{'user'}->{'screen_name'}); $followers_count = mysql_real_escape_string($tweet->{'user'}->{'followers_count'}); //We store the new post in the database, to be able to read it later $ok = mysql_query("INSERT INTO tweets (id ,text ,screen_name ,followers_count, created_at) VALUES ('$id', '$text', '$screen_name', '$followers_count', NOW())"); if (!$ok) {echo "Mysql Error: ".mysql_error();} flush(); } } } ?>[/php]