Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

only the inserts

I have a .sql dump file where some inserts are on multiple lines

I know that every insert line begins with 'insert' and ends with ';'

how can I get only the inserts
Avatar of Rob
Rob
Flag of Australia image

Are you looking for a regular expression?  

^INSERT[^;]+

not sure it will work for multiple lines though
Avatar of rgb192

ASKER

I dont understand
do i use preg_replace or something else
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

preg_match_all("/^INSERT[^;]+/i",...)

what do I put around this statement to get data from infile and send to outfile
$my_text = file_get_contents('FILENAME');
preg_match_all('/INSERT[^;*];/si',$my_text,$matches);
echo '<pre>';
print_r($matches);
echo '</pre>';
As @virmaior has shown, read the file contents into a string variable and then search it using a regular expression
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks