- preg_replace: documentation ( source)
- file_put_contents: documentation ( source)
- rename: documentation ( source)
- feof: documentation ( source)
- fgetc: documentation ( source)
- fwrite: documentation ( source)
- fopen: documentation ( source)
<?php
$file = file_put_contents("/tmp/myfile.txt", "testteststasfasdaskdjfbasdlkfbaslkdcjnbal;dfn");
$tmpFile = file_put_contents("/tmp/mytmpfile.txt","");
$old = fopen($file, 'r');
$new = fopen($tmpFile, 'w');
while (!feof($old)) {
// Your search subject
$subject = '';
// Get $numChars
for($x = 0, $numChars = 100; $x < $numChars; $x++){
$subject .= fgetc($old);
}
// Replace and write to $new
fwrite($new, preg_replace('/[^\P{Cc}\t\r\n]/u', '', $subject));
// Clean out the characters
$subject = '';
}
rename($tmpFile, $file);