2013-03-07 63 views
2

兩種文件的文本,我有兩個文本文件,我創造了這個辦法:合併使用PHP

<?php 
$lines = file('Country.txt'); 
$newf = array(); 
foreach ($lines as $line) 
    $newf[] = substr($line, 2); 
file_put_contents('country2.txt', implode("\n", $newf)); 


$lines2 = file('countryenglish.txt'); 
$newf2 = array(); 
foreach ($lines2 as $line) 
    $newf2[] = substr($line, 3); 
file_put_contents('countryenglish2.txt', implode("\n", $newf2)); 

?> 

兩個顯示數據是這樣的:

Country2.txt: 
Text1Data1 
text1Data2 
text1Data3 
> 
countryenglish2.txt 
Text2Data1 
text2Data2 
text2Data3 

我想顯示:

Text2Data1Text1Data1 
text2Data2text1Data2 
text2Data3text1Data3 

在此先感謝您的幫助!

回答

2

你可以嘗試這樣的事:內串之間

$lines = file('Country.txt'); 
$lines2 = file('countryenglish.txt'); 

foreach ($lines as $key => $val) { 
    $lines[$key] = $val.$lines2[$key]; 
} 

file_put_contents('countryenglish2.txt', implode("\n", $lines)); 
1

從你的功能,你可以這樣做:

$newf3 = array(); 
$to = count($newf2); 

for ($i=0; $i<$to; $i++) { 
    $newf3[] = $newf2[$i] . $newf1[$i]; 
} 

print_r($newf3);