Sorry guys, I got stuck on this:
$data_update = preg_replace($id.'(.*?)'.$s.PHP_EOL, $id.$1.$s.$text.PHP_EOL, $data_update, 1);
$id = '23423';
$s = '|';
$text = 'content to insert';
Basically what I am trying to do is match everything that's between $id and a PHP End of Line in a flat file text that has multiple lines and replace it with the same line that has some content inserted right before the end of line. And I have the "1" modifier at the end because I want this to happen ONLY on the line that matches that id.
What am I doing wrong?
$s="|"? Please post the line example. Maybe you needpreg_replace('/\b(' . $id . '\b.*)(\R)/', '$1 ' . $text . '$2', $data_update, 1);? See this PHP demo.$data_update = "23423 in between some text".PHP_EOL;$data_update .= "00000 in between some more text".PHP_EOL;$data_update .= "11111 in between even more text".PHP_EOL;