<?php $keys = array(); $tmp = file('1.txt'); foreach ($tmp as $v) { $v = trim($v); if (empty($v)) {continue;} $keys[] = $v; } $output = ''; $tmp = file('2.txt'); foreach ($tmp as $v) { $v = trim($v); if (empty($v)) {continue;} if (strpos($v,'[KEY]')===false) { echo "INVALID_STR:$v<br>\r\n"; continue; } foreach ($keys as $key) { $output .= str_replace('[KEY]',$key,$v)."\r\n"; } } file_put_contents('3.txt',$output); echo 'DONE!';
result = open('result.txt', 'w')for text in open('text.txt'): for numb in open('numb.txt'): newline = text.replace('[KEY]', numb.rstrip()) result.write(newline)