我的電話號碼的文本文件,如下圖所示:如何通過線從一個文本文件中提取串線到另一個文本文件
2348089219281 2348081231580 2347088911847 2347082645764 2348121718153 2348126315930 2348023646683。
我想提取的每個號碼,從它剝去+234
並用0
替換,則在修改的號碼前面添加以下文本"Names" . "\t"
。
然後我想插入一個新的文本文件(行由行)這個新的字符串.. 這是我得到的代碼的new_textFile我寫道:
名稱00urce ID#3
名稱00urce ID#3
這裏是我的代碼:
$this_crap_file = fopen($old_file_name, "r");
$total_number_lines_for_this_crap_file = count($this_crap_file);
while(!feof($this_crap_file))
{
$the_new_writing = fopen($new_file_name, "a");
$the_string = substr_replace($this_crap_file, "0", 0, 4);
$new_string = "Names" . "\t" . 0 . $the_string . "\n";
fwrite($the_new_writing, $new_string);
}
fclose($this_crap_file);
你似乎沒有從文件中讀取任何東西。使用'fgets'來讀取文件中的行。 – apokryfos
您應該將打開新文件的fopen()行移至while循環之前。就像現在一樣,您在通過循環的每次迭代中打開新文件。 –
一開始? http://www.phpliveregex.com/p/fNz click preg_replace – Andreas