Skip to content

Instantly share code, notes, and snippets.

@inez
Last active January 29, 2016 01:13
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 inez/34c0b3be3f239caf454b to your computer and use it in GitHub Desktop.
Save inez/34c0b3be3f239caf454b to your computer and use it in GitHub Desktop.
<?php
$txtOrig = $txt = file_get_contents('bad.txt');
function test($str) {
preg_replace_callback("/test/u", function($matches) { return ''; }, $str);
return preg_last_error() === 4 /* PREG_BAD_UTF8_ERROR */;
}
$i = 0;
while ( strlen ( $txt ) > 0 ) {
$txt = substr($txt, 1);
if (test($txt) === false) {
break;
}
$i++;
}
echo substr($txtOrig, $i - 5, 15);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment