i have a file which contains a lot of update query and some other data i need to get the update query from that file using regular expression
my file contains :
2012-03-14 23:29:24 WebModule[]update PAYOUT_HDR set C_ELNO='665656' where N_ID='68' and D_TO=to_date('24/02/2012','dd/MM/yyyy') 2012-03-14 23:57:57 WebModule[]update address_dtl set C_FIRM_NAME='MISS', c_fname='gggg', c_lname='testtt.G',c_addr1='test
',c_addr2='test',c_addr3='test,
testtt',c_district='31001',c_state='27',c_zip_code='444',c_tele_no='555555',c_mobile='444444',c_email='4444@44.com' where n_id=522 and c_type='666'
i tried
preg_match_all("/\update (.*)\)/i", $contents, $matches, PREG_SET_ORDER);
but its not working. Please help me to fix this issue
preg_match_all("/update (.*\))/i", $contents, $matches, PREG_SET_ORDER);
ok if the query ends with a ) but i need all update queries
If that is just a string in your file then you can read that file and get all the data into a variable and after that you can split that string like:-
$array = explode(" WebModule[]",$string);
echo "<pre>";
print_r($array);
$string is the variable that keeps the entire string.
您无需在更新中转义“ u”-假设您正在调用perl模式(PCRE)
/update (.*)\)/i
You have an error in your regex. The below works with your sample input.
preg_match_all("/update (.*\))/i", $contents, $matches, PREG_SET_ORDER);
That said, your current approach only matches queries that end with a ).
Update
This will get both update queries from you example string:
<?php
$contents = "2012-03-14 23:29:24 WebModule[]update PAYOUT_HDR set C_ELNO='665656' where N_ID='68' and D_TO=to_date('24/02/2012','dd/MM/yyyy') 2012-03-14 23:57:57 WebModule[]update address_dtl set C_FIRM_NAME='MISS', c_fname='gggg', c_lname='testtt.G',c_addr1='test
',c_addr2='test',c_addr3='test,
testtt',c_district='31001',c_state='27',c_zip_code='444',c_tele_no='555555',c_mobile='444444',c_email='4444@44.com' where n_id=522 and c_type='666'";
$parts = preg_split('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $contents);
$updates = array();
foreach($parts as $part){
if(!trim($part)){
continue;
}
preg_match_all("/update.*/si", $part, $matches);
if(count($matches)){
$updates[] = $matches[0][0];
}
}
print_r($updates);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.