假设我必须遵循 php 脚本:
$str = "be43f751d380a70d13287006a5f7795a";
$arr = str_split($str, 2);
$strT = implode("", substr_replace($arr ,"",-1));
printf('%s:%s' . PHP_EOL, $str, $strT);
输出:be43f751d380a70d13287006a5f7795a:b4f5d8a01270af75
这适用于单个字符串,但如果我想将其应用于多个字符串,一个包含多个字符串且行尾的文件:
cat strings.txt
dc7380f92396b65be0c9dc2fda593acc
e5a391e5b84ebcd51dc467de52f88558
4ec7814976d12b40638fbe311856f84f
期望的输出:
dc7380f92396b65be0c9dc2fda593acc:d78f29b5ecd2d53c
e5a391e5b84ebcd51dc467de52f88558:ea9eb4bd1c6d5f85
4ec7814976d12b40638fbe311856f84f:4c847d2468b315f4
如果我们可以在命令行中自行指定文件,那就太好了:
php script.php strings.txt > trimmed.txt
谢谢!