Skip to content

Instantly share code, notes, and snippets.

@ayebare
Last active May 10, 2017 07:13
Show Gist options
  • Select an option

  • Save ayebare/72fa52afd7a04fcaf4db1a7d9aa59ad3 to your computer and use it in GitHub Desktop.

Select an option

Save ayebare/72fa52afd7a04fcaf4db1a7d9aa59ad3 to your computer and use it in GitHub Desktop.
Cleaning invalid characters in a list of xml files
<?php
$path_to_xmls = 'updated/problem-updated/*.{wxr,xml}';
$files = glob( $path_to_xmls, GLOB_BRACE );
foreach ( $files as $file ) {
echo "{$file} \n";
$path_to_file = $file;
$file_contents = file_get_contents( $path_to_file );
$file_contents = preg_replace( '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', '', $file_contents );
file_put_contents( $path_to_file, $file_contents );
}
echo 'done';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment