import re with open('approved_school.php', 'r') as f: content = f.read() # Replace the layout start layout_start_replacement = """
""" content = re.sub(r'
\s*
\s*<\?php if \(!\$isApproved\): \?>', layout_start_replacement, content) # Replace the layout end. Wait, currently it is: #
#
# #
#
# Let's just do string replacement for the end. end_str = """ """ new_end_str = """ """ content = content.replace(end_str, new_end_str) with open('approved_school.php', 'w') as f: f.write(content)