标签:
第一种方式,数组处理
<?php $str = file_get_contents(‘a.txt‘); $arr = explode(PHP_EOL,$str); $result = array(); foreach($arr as $v) { $result[] = trim(substr($v,6)); } $result = array_filter($result); $text = ‘‘; foreach($result as $v) { $text .= $v.PHP_EOL; } file_put_contents(‘b.txt‘,$text); ?>
第二种方式,正则直接替换
<?php $str = file_get_contents(‘a.txt‘); $result = preg_replace(‘/\d+\.\s+/‘,‘‘,$str); var_dump($result); file_put_contents(‘c.txt‘,$result); ?>
标签:
原文地址:http://www.cnblogs.com/chenqionghe/p/4293852.html