Let’s say I have to following php script:
$str = "be43f751d380a70d13287006a5f7795a";
$arr = str_split($str, 2);
$strT = implode("", substr_replace($arr ,"",-1));
printf('%s:%s' . PHP_EOL, $str, $strT);
Outputs: be43f751d380a70d13287006a5f7795a:b4f5d8a01270af75
This works with a single string, but what if I want to apply this to more than one string, A file with multiple strings with line endings:
cat strings.txt
dc7380f92396b65be0c9dc2fda593acc
e5a391e5b84ebcd51dc467de52f88558
4ec7814976d12b40638fbe311856f84f
Desired Output:
dc7380f92396b65be0c9dc2fda593acc:d78f29b5ecd2d53c
e5a391e5b84ebcd51dc467de52f88558:ea9eb4bd1c6d5f85
4ec7814976d12b40638fbe311856f84f:4c847d2468b315f4
It would be great if we can specify the file in the command line it self:
php script.php strings.txt > trimmed.txt
Thank you!
Well, I’d also advise reading php manual, however not foreach, but file() function. This could be done like: