import re file_path = 'includes/layout/footer.php' with open(file_path, 'r', encoding='utf-8') as f: content = f.read() # Define the new content for Record Visit Modal record_visit_modal = """ " # Define the new content for Edit Visit Modal edit_visit_modal = """ " # Replace the blocks start_marker = "" end_marker = "" start_idx = content.find(start_marker) end_idx = content.find(end_marker) if start_idx != -1 and end_idx != -1: new_content = content[:start_idx] + record_visit_modal + "\n\n" + edit_visit_modal + "\n\n" + content[end_idx:] with open(file_path, 'w', encoding='utf-8') as f: f.write(new_content) else: print("Could not find markers")