Getting rid of an empty string, but keeping other intact

After deleting the record from the file, I left an empty line where the record used to be, and I would like to know how to get rid of it at the same time the script was running.

The data.txt file contains the following data:

1 12 123 (line to be deleted) 1234 (blank line, carriage return) 

plus an empty line at the bottom of the line that I would like to save, but not left after deleting the record.

what I left after recording was deleted:

 1 12 1234 (blank line, which I want to keep intact) 

Here is my real working code below:

 $bodycont = preg_replace("/\b({$_POST['inscripnum1']})\b/","",$index); 

How can I implement something on the same line to remove the line that had the number?

Any help would be greatly appreciated.

thanks

+6
source share
1 answer

Regular expression line break capture:

 $bodycont = preg_replace("/\b({$_POST['inscripnum1']})\b\n/","",$index); 
+2
source

Source: https://habr.com/ru/post/916873/


All Articles