PHP expression help I think

Discussion in 'PHP' started by bigmike7801, Jun 25, 2008.

  1. #1
    I have a text file that has the following information:
    
    INSERT INTO `ad_count` VALUES('2008-06-25',232351,2);
    INSERT INTO `ad_count` VALUES('2008-06-25',232352,1);
    INSERT INTO `ad_count` VALUES('2008-06-25',232357,0);
    INSERT INTO `ad_count` VALUES('2008-06-25',232362,49);
    INSERT INTO `ad_count` VALUES('2008-06-25',232363,8);
    INSERT INTO `ad_count` VALUES('2008-06-25',234415,41);
    INSERT INTO `ad_count` VALUES('2008-06-25',234416,0);
    INSERT INTO `ad_count` VALUES('2008-06-25',234417,32);
    INSERT INTO `ad_count` VALUES('2008-06-25',234419,32);
    INSERT INTO `ad_count` VALUES('2008-06-25',292147,0);
    INSERT INTO `ad_count` VALUES('2008-06-25',343541,1);
    CREATE TABLE run_date (run_date char, ad_count int);
    INSERT INTO `run_date` VALUES('2008-06-24',568);
    INSERT INTO `run_date` VALUES('2008-06-25',583);
    CREATE TABLE admarket_market (id int, domain BLOB, name BLOB, display_name BLOB, redmatch_affiliate int, ad_expire_days int, published_data_lifetime int, notification_email BLOB, agent_max_results int, agent_sender BLOB, agent_duration_min int, agent_duration_max int, hotjobs_login BLOB, hotjobs_password BLOB, hotjobs_profile_id_7 BLOB, hotjobs_profile_id_30 BLOB, hotjobs_reply BLOB, hotjobs_contact_newspaper BLOB, hotjobs_contact_company BLOB, hotjobs_contact_email BLOB, hotjobs_contact_phone BLOB, mastercat_sync int, hotjobs_account_id BLOB, hotjobs_account_tag_id BLOB, hotjobs_profile_id BLOB, hotjobs_version real, hotjobs_send_once int);
    INSERT INTO `admarket_market` VALUES(15,'tdn.com','admarket','Ad Market','',1,1,'jim.wallingford@lee.net,michael.rogers@lee.net',0,'',0,0,'','','','','','','','','',0,'','','','',0);
    CREATE TABLE admarket_market_synonym (market_id int, words BLOB);
    CREATE TABLE admarket_field (name BLOB, display_name BLOB, value_type BLOB, udl_fallback BLOB);
    INSERT INTO `admarket_field` VALUES('title','Title','BLOB','');
    INSERT INTO `admarket_field` VALUES('bedrooms','Bedrooms','float','rooms');
    INSERT INTO `admarket_field` VALUES('bathrooms','Bathrooms','float','');
    INSERT INTO `admarket_field` VALUES('color','Color','BLOB','');
    INSERT INTO `admarket_field` VALUES('company_name','Company Name','BLOB',''); 
    INSERT INTO `admarket_ad` VALUES(7693992,15,11,73521,'liner','','','Employment Advertising Regulations in
    The Daily News
    Every employment ad must clearly state what type of employment is being offered. All advertised statements must be accurate and not designed to mislead the reader. Employment agencies must state their name. If name does not include Personnel or Agency, the words "agency" or "fee" must be in the ad. "No Fee" or "Temporary" positions do not need "agency" or "fee". Employment requiring an investment must run under Business Opportunities. It is the advertiser''s responsibility to be aware of Federal, State & Local laws and regulations pertaining to employment. It is The Daily News'' right to refuse all advertising which does not comply with these regulations.','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232229";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694078,15,11,83706,'liner','','','Missing Your Daily News? Call Circulation
    577-2571','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232133";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694185,15,11,83708,'liner','','','Our Circulation Dept. can answer all of your delivery questions. Call 577-2571.','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232156`;}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694232,15,11,83711,'liner','','','The Daily News
    Delivered to Your Door!
    Call 577-2571 Today!','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232235";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694270,15,11,83715,'liner','','','Missing Your Daily News? Call Circulation
    577-2571','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232258";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694446,15,11,83716,'liner','','','Do you have questions about your Daily News subscription? Call Circulation 577-2571','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232279`;}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694056,15,11,83718,'liner','','','Subscribe to
    The Daily News today!
    Call Circulation 577-2571','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232118";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); 
    PRAGMA writable_schema=ON;
    INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)VALUES('table','admarket_ad_index','admarket_ad_index',0,'CREATE VIRTUAL TABLE admarket_ad_index using fts1 (id int, text, tokenize porter)');
    CREATE TABLE admarket_ad_index_content(c0id, c1text);
    INSERT INTO `admarket_ad_index_content` VALUES(7694081,' Big profits usually mean big risk. For free info about avoiding investment scams, write the
    Federal Trade Commission at Washington D.C., 20580.
    Or call National Fraud Info Ctr. 1-800-876-7060 '); 
    
    Code (markup):
    But I want to extract just this information and place it in a text file:
    INSERT INTO `admarket_ad` VALUES(7693992,15,11,73521,'liner','','','Employment Advertising Regulations in
    The Daily News
    Every employment ad must clearly state what type of employment is being offered. All advertised statements must be accurate and not designed to mislead the reader. Employment agencies must state their name. If name does not include Personnel or Agency, the words "agency" or "fee" must be in the ad. "No Fee" or "Temporary" positions do not need "agency" or "fee". Employment requiring an investment must run under Business Opportunities. It is the advertiser''s responsibility to be aware of Federal, State & Local laws and regulations pertaining to employment. It is The Daily News'' right to refuse all advertising which does not comply with these regulations.','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232229";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694078,15,11,83706,'liner','','','Missing Your Daily News? Call Circulation
    577-2571','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232133";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694185,15,11,83708,'liner','','','Our Circulation Dept. can answer all of your delivery questions. Call 577-2571.','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232156`;}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694232,15,11,83711,'liner','','','The Daily News
    Delivered to Your Door!
    Call 577-2571 Today!','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232235";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694270,15,11,83715,'liner','','','Missing Your Daily News? Call Circulation
    577-2571','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232258";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694446,15,11,83716,'liner','','','Do you have questions about your Daily News subscription? Call Circulation 577-2571','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232279`;}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    INSERT INTO `admarket_ad` VALUES(7694056,15,11,83718,'liner','','','Subscribe to
    The Daily News today!
    Call Circulation 577-2571','',1208365589,1214399294,1214399294,1208329200,1214463599,87,0,0,0,NULL,'a:0:{}','a:1:{i:0;s:6:"232118";}','a:0:{}','tdn.com',0,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'P.O. BOX 189',NULL,NULL,98632,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
    Code (markup):
    Basically anything that has INSERT INTO `admarket_ad`

    Any help would be greatly appreciated.

    Thanks - Mike
     
    bigmike7801, Jun 25, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    why not doing it with an editor? mostly all inserts are combined row after row... so you have to cut the first part and maby last part of the file...
     
    EricBruggema, Jun 26, 2008 IP
  3. bokiatenxi

    bokiatenxi Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it's a bit easy if you assume that there is only one info per line because of the fgets (reads a line from an external file) function..

    something like this would do...

    
    <?php
    $inhandle = @fopen("/tmp/inputfile.txt", "r");
    $outhandle = @fopen("/tmp/outputfile.txt", "w");
    if ($inhandle) {
        while (!feof($inhandle)) {
            $buffer = fgets($inhandle, 4096);
            if(stripos($buffer, 'INSERT INTO `admarket_ad`') != FALSE) {
              fwrite($outhandle, $buffer);
            }
        }
        fclose($inhandle);
    }
    fclose($outhandle);
    ?>
    
    Code (markup):
     
    bokiatenxi, Jun 26, 2008 IP