law Posted May 3, 2009 Share Posted May 3, 2009 Ok I have never done anything like this before and it shows! I have 3 arrays array1 is from a database of commands array2 is from a database of names array3 is a imap request to an email account. I then read the newest email and make it this array. I would like to text a message to my email account. My message will include something like: "@work DO math." I would like to process the message and have the computer understand that I am not home so it should use its extra cpu cycles to run X program in this case Math. Well here is how I am doing this "so far." I am up for suggestions bc I know there must be a more efficient way of doing this. <?php include_once('./dbconfig.php'); $mbox = imap_open ("{imap.googlemail.com:993/imap/ssl}INBOX", "email name", "email password", OP_READONLY) or die("can't connect: " . imap_last_error()); $status = imap_status($mbox, "{imap.googlemail.com:993/imap/ssl}INBOX", SA_ALL); if ($status) { $total_msgs = $status->messages; echo "Messages: " . $status->messages . "\n"; echo "Recent: " . $status->recent . "\n"; echo "Unseen: " . $status->unseen . "\n"; echo "UIDnext: " . $status->uidnext . "\n"; echo "UIDvalidity:" . $status->uidvalidity . "\n<br/>"; } else { echo "imap_status failed: " . imap_last_error() . "\n"; } $message = nl2br(imap_body ($mbox , 4)); ////////////////////////////////// Checking for parts //////////////////// $pieces = explode(" ", $message); print_r($pieces); function funct_symbol ($piece, $symbol){ $var = strrpos($piece, $symbol); if ($var === false) { $var= "no"; } else { $var = "yes"; } return $var; } $q="SELECT building_symbol FROM locations"; $sql = mysql_query($q); $buildings_row = mysql_fetch_array($sql); $q="SELECT command_symbol FROM commands"; $sql = mysql_query($q); while ($commands_row = mysql_fetch_array($sql)){ $i = 0; //pieces array foreach ($pieces as $b){ //echo $b[0]; $msg[$commands_row[0]][$i] = funct_symbol($b[0], $commands_row[0]); //echo $msg[$commands_row[0]][$i] ."=".$b[0]." which may contain ". $commands_row[0]."<br/>"; $i++; } } echo "<br/><br/><br/>----------------------------<br/>"; echo $msg['@'][0] . $pieces[0]; echo "<br/><br/><br/>----------------------------<br/>"; imap_close($mbox); ?> My first major problem hits @ the for each loop.. here is an example of my $message string: Array ( [0] => @work [2] => ?processlist /> -- /> ================================================================== /> This [5] => mobile [6] => text [7] => message [8] => is [9] => brought [10] => to [11] => you [12] => by [13] => AT&T /> ) Here is what $b[0] outputs as the pointer gets moved through the array @?///mtmibtybA/ I'm really lost here on this one.. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 You want to compare 3 arrays? So what are the 3 arrays? I'm not following. Quote Link to comment Share on other sites More sharing options...
law Posted May 3, 2009 Author Share Posted May 3, 2009 I apologize I am a self taught coder... I just write it in my own logic.. which is dangerous! "array1 is from a database of commands array2 is from a database of names array3 is a imap request to an email account. I then read the newest email and make it this array." Array 1 = $commands_row (what i would like to happen) <code>$q="SELECT command_symbol FROM commands"; $sql = mysql_query($q) $commands_row = mysql_fetch_array($sql); </code> Array 2 = $buildings_row (places i could be) <code>$q="SELECT building_symbol FROM locations"; $sql = mysql_query($q); $buildings_row = mysql_fetch_array($sql);</code> Array3= $pieces (email message) <code>$message = nl2br(imap_body ($mbox , 4)); $pieces = explode(" ", $message);</code> The places/locations/buildings concept is added to this because i have a similar routine every day. I go to the office I complete my tasks. Then I am free to go. At this point I travel to a laboratory and do research as a second job. I only get paid for 2 hours a day at the lab (the maximum amount they can afford to pay me). So if i message my email account @lab. I can add logic to tell it to stop what it is doing in 2 hours because I will be home. At that point I will want to use the computer for gaming/ect ect.. needing all cpu cycles possible. If I can get this working it will be a huge help to the Staph lab I work at because my computer will be much more efficient allowing me to crunch and extensive amount of their data for correlations through regression analysis. ================For those who want a concise version of my problem ================================ "foreach ($pieces as $b)" print_r ($pieces) gives me a full word print_r ($b) is out putting the first letter of the word? I need this issue resolved so that I may move on with the project. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 So what are commands? Can you list some values in each of those 3 arrays (for example purposes) and tell me what you want done with those values? I get the concept now, but I don't understand how those 3 values work together. Quote Link to comment Share on other sites More sharing options...
law Posted May 4, 2009 Author Share Posted May 4, 2009 well i am like a kid with a new hammer.. i want to re purpose this code to run on multiple machines of mine once it is finished.. that is the reason i am using a database to add commands in and out.. here is my current database schema Table : location Column : id, building_name, building_symbol Building name is the full name of a place. The building symbol is the abbreviation of that building. These are my possible locations. I want to be able to add them via a database and eventually I will add additional fields to accompany specific time slots. As well as % of cpu cycles available. IE if I am at a friends house. I would like to be able to log into my computer to get gamefiles/maps if we needed them. I would only want it to use 60% of the excess cycles in this case. Table : commands Column : id, command_name, command_symbol, command_description, required_id *Description : The commands table holds commands such as @,DO,START these commands are kept in a table so that I may add more in the future without having to modify my parsing code.* Example: ID: 1 CommandName: At Location CommandSymbol: @ CommandDescription: My current location RequiredID: 0 Required id would be used for a command such as DO. I would like for DO to only work if it is given a START time. So the required id is the number of the start command. Example Email MSG : "@work DO defrag START 13:00" I would like to parse the message and tell the script a) I'm at work (use all extra cpu cycles and ram) b) Run the Defrag program c) Start the program at 1:00pm Once I can get the php logic down, I can use it to talk to the command line to handle all of my needs. I just need to get all of the filtering logic in line. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 I'm not sure if you can tell a program to start at 1 PM or any specified time using PHP. I know CRON can do it, but you probably don't want CRON to run every second. Also, what's the defrag program? Quote Link to comment Share on other sites More sharing options...
law Posted May 4, 2009 Author Share Posted May 4, 2009 I could set up a scheduled task if needed, or I can log the time in the database and have php check every 30 min for a scheduled task for it to perform. I can fight that battle when I get there. I just need to figure out how to take 3 arrays and keep the data that matches up in 2 of the 3 arrays. What is the best way to take an array of data and search it using another array of search terms? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.