Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Created December 27, 2021 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanpejcic/14eae87cdf2276f896b40f626ba7abc5 to your computer and use it in GitHub Desktop.
Save stefanpejcic/14eae87cdf2276f896b40f626ba7abc5 to your computer and use it in GitHub Desktop.
<?php
ini_set( 'pcre.backtrack_limit', '50000000000' );
ini_set( 'pcre.recursion_limit', '50000000000' );
$inputfile = fopen( 'inputfile.sql', 'r' ); // replace this before running
$outputfile = fopen( 'outputfile.sql', 'w' ); // replace this before running
$regex = '/myregex/s';
$lines = 0;
if ( $inputfile ) {
while ( ( $buffer = fgets( $inputfile ) ) !== false ) {
$lines ++;
echo 'Line:' . $lines . PHP_EOL;
$c = preg_replace( $regex, '', $buffer, -1, $count );
fwrite( $outputfile, $c );
}
if ( ! feof( $inputfile ) ) {
echo "Error: unexpected fgets() fail\n";
}
fclose( $inputfile );
fclose( $outputfile );
echo "Done!\n";
} else {
echo "Input issue!\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment