How to delete text from file using preg_replace() function in PHP?
Reads a file, matches pattern using regex, replaces with empty string, and saves.
<?php
$content = "DEBUG [2026-09-01]: Test message.\nINFO: User logged in.\nDEBUG [2026-09-01]: Another trace.";
$cleanedContent = preg_replace('/DEBUG.*?\n/s', '', $content);
echo "Cleaned File Content:\n$cleanedContent\n";
?>Cleaned File Content: INFO: User logged in. DEBUG [2026-09-01]: Another trace.