21,882
社区成员
发帖
与我相关
我的任务
分享
<?php
$fp = fopen("20171119-1.txt","r");
$str = "";
while(! feof($fp))
{
$str .= fgets($fp);//."<br />";//."\r\n";//
}
//echo $str;不显示
$cyfile = fopen("20171119-1.txt", "w") or die("Unable to open file!");
function insertToStr1($str, $i, $substr){
$startstr="";
for($j=0; $j<$i; $j++){
$startstr .= $str[$j];
}
$laststr="";
for ($j=$i; $j<strlen($str); $j++){
$laststr .= $str[$j];
}
$str = ($startstr . $substr . $laststr);
return $str;
}
$newStr=insertToStr1($str, 2, "!@!");
fwrite ($cyfile,$newStr);
fclose($cyfile);
?>
$filename = '20171119.txt';
echo "操作前原始\n";
readfile($filename);
$ar = file($filename);
foreach($ar as $k=>$v) $ar[$k] = insertToStr1($v, 2, "!@!");
file_put_contents($filename, $ar);
echo "操作后\n";
readfile($filename);
function insertToStr1($str, $i, $substr) {
return substr($str, 0, $i) . $substr . substr($str, $i);
}
$arr = range('110000000','110024756');
file_put_contents('20171119-1.txt', implode($arr,"\r\n"));
$str = file_get_contents('20171119-1.txt');
$str = preg_replace("#(..)(.+)#",'\1!@!\2',$str);
file_put_contents('20171119-1kkk.txt', $str);
echo('done!');