I use insert_with_markers in a couple of my plugins to add some small bits of code to the htaccess file. What I’m unclear about is how to remove the code and markers.
For example, if I call the function like this:-
insert_with_markers($htaccess, "marker","RewriteBase /foobar");
The result in htaccess is:-
# BEGIN marker
RewriteBase /foobar
# END marker
I can use insert_with_markers, with an empty string, like so:-
insert_with_markers($htaccess, "marker","");
Which removes all the code, but the markers remain, like this:-
# BEGIN marker
# END marker
Does anybody know of a clean way to remove the markers as well?… that doesn’t involve filtering the htaccess file with regex? I would like to be able to uninstall my plugins and remove all the traces if possible.
2 Answers
If you know the exact code that is inserted, then read the htaccess
file with a function that contains fread
command, and do a search for your inserted text, replacing the found text with an empty string. Then fwrite
the text to the htaccess
file.
If you are just looking for a way to remove the # BEGIN MARKER / # END MARKER
text, then use the same process.