Read in file, replace [linebreak char] with ?? and create new string/file
Tried both strtr and str_replace but only manage to replace known chars, not random.
I already tried:
$file = file_get_contents('./tel6.out', true);
$s=strtr($file, array( '' => '??' ));
Format of source-file:
$st= "0090C9
00AV0X7Y79T543C
00AV0X6Y103T245C
00AV0X60Y103T248C
00AV0X101Y103T24B8
00AV0X131Y103T24BB
00AV0X10Y111T0484
00AV0X63Y111T048C
00AV0X133Y111T04BA
00AV0X151Y111T04BA
00AV0X166Y56T1499
00AV0X167Y61T1496
00AV0X17Y124T2491
00AV0X11Y129T2490
00AV0X14Y125T248F
00AV0X14Y130T248B
00AV0X17Y129T2496
00AV0X10Y134T248B
00AV0X34Y134T2491
00AV0X10Y149T2491
00AV0X10Y152T248B";
$ret = "";
//split the string by newline
$splitted = trim(explode("
", $st));
foreach ($splitted as $s2)
{
//overwrite a random char in this chunk of the string with the first '?'
$s2[rand(0, count($s2))] = '?';
//overwrite a random char in this chunk of the string with the second '?'
$s2[rand(0, count($s2))] = '?'; //this '?' may overwrite the first one
//concatenate a string with this chunk plus '??' (that stand now instead of newline)
$ret = $ret . $s2 . "??";
}
//show the resulting string
var_dump($ret);
Note: may happen the two random '?' are put in the same place for a chunk of string, so resulting only one '?' in a chunk of string. (Of course it can be prevented).
It's not required to know the char to replace, if you overwrite it.