I'm migrating a directory of files containing fairly simple ASP code over to a PHP server and I need to modify the contents of all the files with a find and replace mechanism. I'm not great with regular expressions, but I've used this to change a few things already:
find . -name "*.php" -print0 | xargs -0 -n 1 sed -i -e 's/oldstring/newstring/g'
I have some complex strings I need to replace though. See the following:
FROM:
<% if request("page") = "" then %>
TO:
<?php if(!isset($_GET['page']) || !$_GET['page']){ ?>
This one, the * can be any number, then keep that number where the * is on the "TO".
FROM:
<% elseif request("page") = "*" then %>
TO:
<?php } elseif($_GET['page'] == '*'){ ?>
And the last one is pretty simple. FROM:
<% end if %>
TO:
<?php } ?>
If I can run this in bulk, recursively in a directory, this will fix 98% of all the ASP code in these files. I've tried to escape these strings in several ways, but cannot figure out how to get it to run. Any help is appreciated!