I want to add text to a file after specified string using PHP.
For example, I want to add the word 'ldaps' after #redundant LDAP {
string
I used this code without result:
$lines = array();
foreach(file("/etc/freeradius/sites-enabled/default") as $line) {
if ("redundant LDAP {" === $line) {
array_push($lines, 'ldaps');
}
array_push($lines, $line);
}
file_put_contents("/etc/freeradius/sites-enabled/default", $lines);
The only thing this code does is put lines into an array and then insert to the file without adding the word.