Skip to content

Commit

Permalink
feat: add fix strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nrenvoise-ubitransport committed Jun 18, 2020
1 parent bc81965 commit be35fca
Showing 2 changed files with 57 additions and 0 deletions.
13 changes: 13 additions & 0 deletions string/fix_string/fix_string.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

function fixString(string $stringToFix)
{
$fixedString = str_replace('ï', 'ë', $stringToFix);
$fixedString = str_replace('é', 'é', $fixedString);
$fixedString = str_replace('Ã', 'à', $fixedString);
$fixedString = str_replace('è', 'è', $fixedString);

return $fixedString;
}

echo fixString($argv[1]);
44 changes: 44 additions & 0 deletions string/fix_string/fix_strings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

function fixFile(string $fileName) {
if ($fileName === '.' || $fileName === '..') {
return;
}

$fileContent = file_get_contents(__DIR__ . "/file_to_fix/$fileName");

return fixString($fileContent);
}

function fixString(string $stringToFix)
{
$fixedString = $stringToFix;
$fixedString = str_replace('ï', 'ï', $fixedString);
$fixedString = str_replace('²', '²', $fixedString);
$fixedString = str_replace('é', 'é', $fixedString);
$fixedString = str_replace('è', 'è', $fixedString);
$fixedString = str_replace('Ã', 'à', $fixedString);
$fixedString = str_replace('à¨', 'è', $fixedString);
$fixedString = str_replace('à§', 'ç', $fixedString);
$fixedString = str_replace('àª', 'ê', $fixedString);
$fixedString = str_replace('àª', 'ê', $fixedString);
$fixedString = str_replace('€', '', $fixedString);
$fixedString = str_replace('ö', 'ï', $fixedString);
$fixedString = str_replace('ë', 'ö', $fixedString);
$fixedString = str_replace('à¹', 'ù', $fixedString);
$fixedString = str_replace('à¢', 'â', $fixedString);
$fixedString = str_replace('à«', 'ê', $fixedString);
$fixedString = str_replace('à»', 'û', $fixedString);
$fixedString = str_replace('à´', 'ô', $fixedString);
$fixedString = str_replace('à¼', 'ü', $fixedString);

return $fixedString;
}

$filesToFix = scandir(__DIR__ . '/file_to_fix');

$fixedStrings = array_map('fixFile', $filesToFix);

array_map(function ($fixedString) {
echo "$fixedString\n";
}, $fixedStrings);

0 comments on commit be35fca

Please sign in to comment.