Skip to content

Instantly share code, notes, and snippets.

@baptistedonaux
Created June 4, 2014 09:54
Show Gist options
  • Save baptistedonaux/cb8e890c6e0fba5b694a to your computer and use it in GitHub Desktop.
Save baptistedonaux/cb8e890c6e0fba5b694a to your computer and use it in GitHub Desktop.
Delete invisible ASCII chars which can generate errors.
<?php
gc_disable();
$content = file_get_contents("db.csv");
if ($content === false) {
echo "ERROR: impossible to read the file.";
die();
}
for($i = 0; $i < strlen($content); $i++) {
$ascii = ord($content[$i]);
if (($ascii < 32 or $ascii > 126) and $ascii != 10) {
$content[$i] = "?";
}
}
if (file_put_contents("new.csv", $content) === false) {
echo "ERROR: impossible to write the new file.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment