Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression

Status
Not open for further replies.

maryer

IS-IT--Management
Jun 10, 2002
16
CY
i need to put this into mysql table
***************************
2003-01-07 01:56:44 : back_up
2003-01-07 01:34:47 : down
****************************
is this right way to do that?

$f_data = file($filename);
foreach($f_data as $str)
$result=(ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2} \s ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $str, $matches));
if ($result) {
$sql = "INSERT INTO downuptable VALUES ('STP', '$down', '$up') order by datetime";
??????

thx in advance

 
Insufficient data for a meaningful answer.

I would split each line of the file at the string " : " (space colon space) to see whether the TD stamp is for an "up" or a "down". I would also throw the TD stamp into a stack so that I could match up ups and downs -- you don't way whether this file guarantees it will always be the case that a "down" immediately following its "up". Want the best answers? Ask the best questions: TANSTAAFL!
 
THINK you are inserting a list of dates into a table from a log file.
You do not need to order when doing an INSERT only when getting the information back using a SELECT.

if( (ereg("([0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})", $first_str, $up_datetime)) && (ereg("([0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})", $second_str, $down_datetime)) )
{
$sql = "INSERT INTO downuptable VALUES ('STP', '$up_datetime[1]', '$down_datetime[1]')";
// run query here
}

To retrieve the information -

SELECT * FROM downuptable ORDER BY #insert_up_date_field_name_here#

Please be more clear on the data you have and the format your retrieving it, as you have specified variables without us knowing what is in them.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top