If you do not want to be something very advanced, this is a simple solution:
Source of testfile.txt
abc def ghi
abc defghi
abc def ghi
abc dfghi
abc defdef ghi
PHP code
<?php
$lines = file('testfile.txt');
foreach ($lines as $line) {
$SearchAndReplace=str_replace('def', 'def 123', $line);
echo $SearchAndReplace.'<br />';
}
?>
Output:
abc def 123 ghi
abc def 123ghi
abc def 123 ghi
abc dfghi
abc def 123def 123 ghi
You can check the PHP documentation about the file function
source
share